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: 18388 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1UboE6-0003OV-9H; Mon, 13 May 2013 10:35:22 +0200 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.72/mailfrontend-8) with esmtp id 1UboE4-0001s9-jq; Mon, 13 May 2013 10:35:22 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753318Ab3EMIfO (ORCPT + 1 other); 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 X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2013.5.13.82416 X-PMX-Spam: Gauge=IIIIIIIII, Probability=9%, Report=' HTML_NO_HTTP 0.1, MULTIPLE_RCPTS 0.1, HTML_00_10 0.05, BODY_SIZE_3000_3999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CP_URI_IN_BODY 0, __HAS_FROM 0, __HAS_HTML 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MULTIPLE_RCPTS_CC_X2 0, __SANE_MSGID 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_NO_WWW 0, __URI_NS ' 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);