From patchwork Thu May 16 08:14:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 2575961 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id E06EFE00E5 for ; Thu, 16 May 2013 08:15:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756113Ab3EPIPJ (ORCPT ); Thu, 16 May 2013 04:15:09 -0400 Received: from mailout4.w1.samsung.com ([210.118.77.14]:32066 "EHLO mailout4.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755941Ab3EPIPD (ORCPT ); Thu, 16 May 2013 04:15:03 -0400 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MMV00189TKYHT40@mailout4.w1.samsung.com> for linux-media@vger.kernel.org; Thu, 16 May 2013 09:15:01 +0100 (BST) X-AuditID: cbfec7f5-b7f376d000001ec6-86-51949584b3b5 Received: from eusync2.samsung.com ( [203.254.199.212]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 8C.1D.07878.48594915; Thu, 16 May 2013 09:15:00 +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 <0MMV00JNCTKOHX00@eusync2.samsung.com>; Thu, 16 May 2013 09:15:00 +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 v3 1/3] media: added managed media entity initialization Date: Thu, 16 May 2013 10:14:32 +0200 Message-id: <1368692074-483-2-git-send-email-a.hajda@samsung.com> X-Mailer: git-send-email 1.7.10.4 In-reply-to: <1368692074-483-1-git-send-email-a.hajda@samsung.com> References: <1368692074-483-1-git-send-email-a.hajda@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrGJMWRmVeSWpSXmKPExsVy+t/xK7otU6cEGrz9JGdxa905VovHG68x W5xtesNu0TlxCbtFz4atrBaH37SzWpzZv5LNYsbkl2wOHB6zO2ayehz+upDFo2/LKkaPz5vk AliiuGxSUnMyy1KL9O0SuDKmtpsUdIlXLD65i7GBcalwFyMnh4SAicSEmRtZIGwxiQv31rN1 MXJxCAksZZR4PWExM4TTxySxff5FsCo2AU2Jv5tvsoHYIgLyEk96b4B1MAtMZJK4+ncZWEJY wEdiwfn5TCA2i4CqxOJtS1lBbF4BR4m9Ez8xQ6xTlOh+NgGsnlPASWL18kdgthBQzdcbvYwT GHkXMDKsYhRNLU0uKE5KzzXSK07MLS7NS9dLzs/dxAgJq687GJceszrEKMDBqMTDazl9cqAQ a2JZcWXuIUYJDmYlEd4ZqVMChXhTEiurUovy44tKc1KLDzEycXBKNTDOnnXvvsxz7UvaZeI/ 7vMtrdvqtn+a2Hbd4OJlF37Oui15Kf29EPMJTpO6L9unfpu+IltZ6W/BgtgtcT5h+ifDl5Q/ XnlN/bYAQ2mg/7L5jVy7J/h2crxRXKDNtsL3wr2FdkzP/4kF6DYGSht/njP3a20ezycr/4MW wTM2WO3PjPNmi5zlYVKjxFKckWioxVxUnAgAiPd9TwkCAAA= 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 function for media entity. Signed-off-by: Andrzej Hajda Reviewed-by: Sylwester Nawrocki Signed-off-by: Kyungmin Park --- v3: - removed managed cleanup --- drivers/media/media-entity.c | 44 ++++++++++++++++++++++++++++++++++++++++++ include/media/media-entity.h | 5 +++++ 2 files changed, 49 insertions(+) diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c index e1cd132..b1e29a7 100644 --- a/drivers/media/media-entity.c +++ b/drivers/media/media-entity.c @@ -82,9 +82,53 @@ 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. + */ +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); + /* ----------------------------------------------------------------------------- * Graph traversal */ diff --git a/include/media/media-entity.h b/include/media/media-entity.h index 0c16f51..e25730e 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,9 @@ 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); + 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);