From patchwork Thu May 16 08:14:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 2575981 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 80240E00E5 for ; Thu, 16 May 2013 08:15:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756162Ab3EPIPP (ORCPT ); Thu, 16 May 2013 04:15:15 -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 S1755310Ab3EPIPI (ORCPT ); Thu, 16 May 2013 04:15:08 -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-89-519495841866 Received: from eusync2.samsung.com ( [203.254.199.212]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 4D.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 2/3] media: added managed v4l2 control initialization Date: Thu, 16 May 2013 10:14:33 +0200 Message-id: <1368692074-483-3-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+NgFvrCJMWRmVeSWpSXmKPExsVy+t/xK7otU6cEGjzot7S4te4cq8XjjdeY Lc42vWG36Jy4hN2iZ8NWVovDb9pZLc7sX8lmMWPySzYHDo/ZHTNZPQ5/Xcji0bdlFaPH501y ASxRXDYpqTmZZalF+nYJXBlrdz1kLngvXvHr2WamBsYXwl2MnBwSAiYSf189ZoKwxSQu3FvP BmILCSxllPi42a+LkQvI7mOS2D7/IgtIgk1AU+Lv5ptgRSIC8hJPem+wgRQxC0xkkrj6dxmQ w8EhLOAjsf9TBEgNi4CqRMuZSSwgYV4BR4l3W9UhdilKdD+bADaGU8BJYvXyR1B7HSW+3uhl nMDIu4CRYRWjaGppckFxUnqukV5xYm5xaV66XnJ+7iZGSEh93cG49JjVIUYBDkYlHl7L6ZMD hVgTy4orcw8xSnAwK4nwzkidEijEm5JYWZValB9fVJqTWnyIkYmDU6qB8fCWJKXwX9P3r7QI kdtdt+moj0Kny9tVjEoR8R73vpm/nLrvyw5xMwU9Ky4/d8+Tv7ZapO1vlNTW/hGX0Vy3hUfz 4sc27Sv7/z/y0rQ+cCVZS66HwzfafZdFqKHSYo8J7NPbr8+cPXXZPd/YSaJqss6P332+aVDz PnpJzdnyGNFjZgu2/z3WpsRSnJFoqMVcVJwIAL4aitYHAgAA Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This patch adds managed version of initialization function for v4l2 control handler. Signed-off-by: Andrzej Hajda Reviewed-by: Sylwester Nawrocki Signed-off-by: Kyungmin Park Acked-by: Hans Verkuil Acked-by: Laurent Pinchart --- v3: - removed managed cleanup v2: - added missing struct device forward declaration, - corrected few comments --- drivers/media/v4l2-core/v4l2-ctrls.c | 32 ++++++++++++++++++++++++++++++++ include/media/v4l2-ctrls.h | 16 ++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c index ebb8e48..f47ccfa 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls.c +++ b/drivers/media/v4l2-core/v4l2-ctrls.c @@ -1421,6 +1421,38 @@ void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl) } EXPORT_SYMBOL(v4l2_ctrl_handler_free); +static void devm_v4l2_ctrl_handler_release(struct device *dev, void *res) +{ + struct v4l2_ctrl_handler **hdl = res; + + v4l2_ctrl_handler_free(*hdl); +} + +int devm_v4l2_ctrl_handler_init(struct device *dev, + struct v4l2_ctrl_handler *hdl, + unsigned nr_of_controls_hint) +{ + struct v4l2_ctrl_handler **dr; + int rc; + + dr = devres_alloc(devm_v4l2_ctrl_handler_release, sizeof(*dr), + GFP_KERNEL); + if (!dr) + return -ENOMEM; + + rc = v4l2_ctrl_handler_init(hdl, nr_of_controls_hint); + if (rc) { + devres_free(dr); + return rc; + } + + *dr = hdl; + devres_add(dev, dr); + + return 0; +} +EXPORT_SYMBOL_GPL(devm_v4l2_ctrl_handler_init); + /* For backwards compatibility: V4L2_CID_PRIVATE_BASE should no longer be used except in G_CTRL, S_CTRL, QUERYCTRL and QUERYMENU when dealing with applications that do not use the NEXT_CTRL flag. diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h index 7343a27..169443f 100644 --- a/include/media/v4l2-ctrls.h +++ b/include/media/v4l2-ctrls.h @@ -25,6 +25,7 @@ #include /* forward references */ +struct device; struct file; struct v4l2_ctrl_handler; struct v4l2_ctrl_helper; @@ -306,6 +307,21 @@ int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl, */ void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl); +/* + * devm_v4l2_ctrl_handler_init - managed control handler initialization + * + * @dev: Device the @hdl belongs to. + * @hdl: The control handler. + * @nr_of_controls_hint: A hint of how many controls this handler is + * expected to refer to. + * + * This is a managed version of v4l2_ctrl_handler_init. Handler initialized with + * this function will be automatically cleaned up on driver detach. + */ +int devm_v4l2_ctrl_handler_init(struct device *dev, + struct v4l2_ctrl_handler *hdl, + unsigned nr_of_controls_hint); + /** v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging * to the handler to initialize the hardware to the current control values. * @hdl: The control handler.