From patchwork Fri Jan 22 00:56:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 8086161 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-renesas-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 399CD9F744 for ; Fri, 22 Jan 2016 00:57:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7469F20443 for ; Fri, 22 Jan 2016 00:57:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A2FA32042A for ; Fri, 22 Jan 2016 00:57:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751316AbcAVA5d (ORCPT ); Thu, 21 Jan 2016 19:57:33 -0500 Received: from galahad.ideasonboard.com ([185.26.127.97]:58714 "EHLO galahad.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751273AbcAVA5d (ORCPT ); Thu, 21 Jan 2016 19:57:33 -0500 Received: from avalon.access.network (nblzone-211-213.nblnetworks.fi [83.145.211.213]) by galahad.ideasonboard.com (Postfix) with ESMTPSA id EA3992005A for ; Fri, 22 Jan 2016 01:56:27 +0100 (CET) From: Laurent Pinchart To: linux-renesas-soc@vger.kernel.org Subject: [PATCH/RFC v2 22/56] media: Add per-file-handle data support Date: Fri, 22 Jan 2016 02:56:51 +0200 Message-Id: <1453424245-18782-23-git-send-email-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.4.10 In-Reply-To: <1453424245-18782-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> References: <1453424245-18782-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The media devnode core associates devnodes with files by storing the devnode pointer in the file structure private_data field. In order to allow tracking of per-file-handle data introduce a new media devnode file handle structure that stores the devnode pointer, and store a pointer to that structure in the file private_data field. Users of the media devnode code (the only existing user being media_device) are responsible for managing their own subclass of the media_devnode_fh structure. Signed-off-by: Laurent Pinchart Acked-by: Sakari Ailus --- drivers/media/media-device.c | 22 ++++++++++++++++++++++ drivers/media/media-devnode.c | 19 +++++++++---------- include/media/media-devnode.h | 18 +++++++++++++++++- 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index 7b39440192d6..d483a34b6565 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -24,23 +24,45 @@ #include #include #include +#include #include #include #include #include +struct media_device_fh { + struct media_devnode_fh fh; +}; + +static inline struct media_device_fh *media_device_fh(struct file *filp) +{ + return container_of(filp->private_data, struct media_device_fh, fh); +} + /* ----------------------------------------------------------------------------- * Userspace API */ static int media_device_open(struct file *filp) { + struct media_device_fh *fh; + + fh = kzalloc(sizeof(*fh), GFP_KERNEL); + if (!fh) + return -ENOMEM; + + filp->private_data = &fh->fh; + return 0; } static int media_device_close(struct file *filp) { + struct media_device_fh *fh = media_device_fh(filp); + + kfree(fh); + return 0; } diff --git a/drivers/media/media-devnode.c b/drivers/media/media-devnode.c index ebf9626e5ae5..67bac29838d3 100644 --- a/drivers/media/media-devnode.c +++ b/drivers/media/media-devnode.c @@ -154,6 +154,7 @@ static long media_compat_ioctl(struct file *filp, unsigned int cmd, /* Override for the open function */ static int media_open(struct inode *inode, struct file *filp) { + struct media_devnode_fh *fh; struct media_devnode *mdev; int ret; @@ -175,16 +176,15 @@ static int media_open(struct inode *inode, struct file *filp) get_device(&mdev->dev); mutex_unlock(&media_devnode_lock); - filp->private_data = mdev; - - if (mdev->fops->open) { - ret = mdev->fops->open(filp); - if (ret) { - put_device(&mdev->dev); - return ret; - } + ret = mdev->fops->open(filp); + if (ret) { + put_device(&mdev->dev); + return ret; } + fh = filp->private_data; + fh->devnode = mdev; + return 0; } @@ -193,8 +193,7 @@ static int media_release(struct inode *inode, struct file *filp) { struct media_devnode *mdev = media_devnode_data(filp); - if (mdev->fops->release) - mdev->fops->release(filp); + mdev->fops->release(filp); /* decrease the refcount unconditionally since the release() return value is ignored. */ diff --git a/include/media/media-devnode.h b/include/media/media-devnode.h index 17ddae32060d..ce81047cb4fc 100644 --- a/include/media/media-devnode.h +++ b/include/media/media-devnode.h @@ -52,6 +52,20 @@ struct media_file_operations { }; /** + * struct media_devnode_fh - Media device node file handle + * @devnode: pointer to the media device node + * + * This structure serves as a base for per-file-handle data storage. Media + * device node users embed media_devnode_fh in their custom file handle data + * structures and store the media_devnode_fh in the file private_data in order + * to let the media device node core locate the media_devnode corresponding to a + * file handle. + */ +struct media_devnode_fh { + struct media_devnode *devnode; +}; + +/** * struct media_devnode - Media device node * @fops: pointer to struct media_file_operations with media device ops * @dev: struct device pointer for the media controller device @@ -92,7 +106,9 @@ void media_devnode_unregister(struct media_devnode *mdev); static inline struct media_devnode *media_devnode_data(struct file *filp) { - return filp->private_data; + struct media_devnode_fh *fh = filp->private_data; + + return fh->devnode; } static inline int media_devnode_is_registered(struct media_devnode *mdev)