From patchwork Mon May 13 08:34:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 2557031 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 404183FC5A for ; Mon, 13 May 2013 08:35:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753318Ab3EMIfO (ORCPT ); Mon, 13 May 2013 04:35:14 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:24691 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753941Ab3EMIfH (ORCPT ); Mon, 13 May 2013 04:35:07 -0400 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MMQ00M82ABJH680@mailout1.w1.samsung.com> for linux-media@vger.kernel.org; Mon, 13 May 2013 09:35:04 +0100 (BST) X-AuditID: cbfec7f5-b7f376d000001ec6-d9-5190a5b8cf3f Received: from eusync2.samsung.com ( [203.254.199.212]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 62.57.07878.8B5A0915; Mon, 13 May 2013 09:35:04 +0100 (BST) Received: from AMDC1061.digital.local ([106.116.147.88]) by eusync2.samsung.com (Oracle Communications Messaging Server 7u4-23.01 (7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0MMQ005DPAIAQNB0@eusync2.samsung.com>; Mon, 13 May 2013 09:35:04 +0100 (BST) From: Andrzej Hajda To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Sylwester Nawrocki , Sakari Ailus , Kyungmin Park , hj210.choi@samsung.com, sw0312.kim@samsung.com, Andrzej Hajda Subject: [PATCH RFC v2 1/3] media: added managed media entity initialization Date: Mon, 13 May 2013 10:34:44 +0200 Message-id: <1368434086-9027-2-git-send-email-a.hajda@samsung.com> X-Mailer: git-send-email 1.7.10.4 In-reply-to: <1368434086-9027-1-git-send-email-a.hajda@samsung.com> References: <1368434086-9027-1-git-send-email-a.hajda@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrGJMWRmVeSWpSXmKPExsVy+t/xK7o7lk4INPg/ic/i1rpzrBaPN15j tjjb9IbdonPiEnaLng1bWS0Ov2lntTizfyWbxYzJL9kcODxmd8xk9Tj8dSGLR9+WVYwenzfJ BbBEcdmkpOZklqUW6dslcGWc37mZueCyXMXupjdMDYwnJLsYOTkkBEwkHv1+wQxhi0lcuLee rYuRi0NIYCmjxOcnx1ggnD4midZpG8Cq2AQ0Jf5uvskGYosIyEs86b0B1sEsMJFJ4urfZWAJ YQEfiUObDrGC2CwCqhLTZ8xm72Lk4OAVcJLYvYAFYpuiRPezCWDlnALOEge2PACzhYBKzn64 yziBkXcBI8MqRtHU0uSC4qT0XCO94sTc4tK8dL3k/NxNjJCw+rqDcekxq0OMAhyMSjy8HooT AoVYE8uKK3MPMUpwMCuJ8CbNBwrxpiRWVqUW5ccXleakFh9iZOLglGpgLEh83WfIqOv5jK9x 75ytM+d8lGZ+Nds49q+8vtr9/1u3ni7Y9I+rQpFblkOs8tP66GdcFy88bo/asufz5IP+0RPm ZK9v+fEp8Fb8NK0fxxfzHP3RqXfjSkvswaqXhj5fGcr3T6hlTosWu79WVexC8ofW9MaaybkF FzenFunc8uQyWP0q4oSTuBJLcUaioRZzUXEiADFxQpwJAgAA Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This patch adds managed versions of initialization and cleanup functions for media entity. Signed-off-by: Andrzej Hajda Reviewed-by: Sylwester Nawrocki Signed-off-by: Kyungmin Park --- v2: - added missing struct device forward declaration --- drivers/media/media-entity.c | 70 ++++++++++++++++++++++++++++++++++++++++++ include/media/media-entity.h | 6 ++++ 2 files changed, 76 insertions(+) diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c index e1cd132..696de35 100644 --- a/drivers/media/media-entity.c +++ b/drivers/media/media-entity.c @@ -82,9 +82,79 @@ void media_entity_cleanup(struct media_entity *entity) { kfree(entity->links); + entity->links = NULL; } EXPORT_SYMBOL_GPL(media_entity_cleanup); +static void devm_media_entity_release(struct device *dev, void *res) +{ + struct media_entity **entity = res; + + media_entity_cleanup(*entity); +} + +/** + * devm_media_entity_init - managed media entity initialization + * + * @dev: Device for which @entity belongs to. + * @entity: Entity to be initialized. + * @num_pads: Total number of sink and source pads. + * @pads: Array of 'num_pads' pads. + * @extra_links: Initial estimate of the number of extra links. + * + * This is a managed version of media_entity_init. Entity initialized with + * this function will be automatically cleaned up on driver detach. + * + * If an entity initialized with this function needs to be cleaned up + * separately, devm_media_entity_cleanup() must be used. + */ +int +devm_media_entity_init(struct device *dev, struct media_entity *entity, + u16 num_pads, struct media_pad *pads, u16 extra_links) +{ + struct media_entity **dr; + int rc; + + dr = devres_alloc(devm_media_entity_release, sizeof(*dr), GFP_KERNEL); + if (!dr) + return -ENOMEM; + + rc = media_entity_init(entity, num_pads, pads, extra_links); + if (rc) { + devres_free(dr); + return rc; + } + + *dr = entity; + devres_add(dev, dr); + + return 0; +} +EXPORT_SYMBOL_GPL(devm_media_entity_init); + +static int devm_media_entity_match(struct device *dev, void *res, void *data) +{ + struct media_entity **this = res, **entity = data; + + return *this == *entity; +} + +/** + * devm_media_entity_cleanup - managed media entity cleanup + * + * @dev: Device for which @entity belongs to. + * @entity: Entity to be cleaned up. + * + * This function should be used to manual cleanup of an media entity + * initialized with devm_media_entity_init(). + */ +void devm_media_entity_cleanup(struct device *dev, struct media_entity *entity) +{ + WARN_ON(devres_release(dev, devm_media_entity_release, + devm_media_entity_match, &entity)); +} +EXPORT_SYMBOL_GPL(devm_media_entity_cleanup); + /* ----------------------------------------------------------------------------- * Graph traversal */ diff --git a/include/media/media-entity.h b/include/media/media-entity.h index 0c16f51..e3f1604 100644 --- a/include/media/media-entity.h +++ b/include/media/media-entity.h @@ -26,6 +26,8 @@ #include #include +struct device; + struct media_pipeline { }; @@ -126,6 +128,10 @@ int media_entity_init(struct media_entity *entity, u16 num_pads, struct media_pad *pads, u16 extra_links); void media_entity_cleanup(struct media_entity *entity); +int devm_media_entity_init(struct device *dev, struct media_entity *entity, + u16 num_pads, struct media_pad *pads, u16 extra_links); +void devm_media_entity_cleanup(struct device *dev, struct media_entity *entity); + int media_entity_create_link(struct media_entity *source, u16 source_pad, struct media_entity *sink, u16 sink_pad, u32 flags); int __media_entity_setup_link(struct media_link *link, u32 flags);