All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
To: linux-media@vger.kernel.org
Cc: linux-sh@vger.kernel.org
Subject: [PATCH/RFC 22/48] media: Add per-file-handle data support
Date: Thu, 17 Dec 2015 08:40:00 +0000	[thread overview]
Message-ID: <1450341626-6695-23-git-send-email-laurent.pinchart+renesas@ideasonboard.com> (raw)
In-Reply-To: <1450341626-6695-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com>

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 <laurent.pinchart+renesas@ideasonboard.com>
---
 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..285f7d79d848 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -24,23 +24,45 @@
 #include <linux/export.h>
 #include <linux/ioctl.h>
 #include <linux/media.h>
+#include <linux/slab.h>
 #include <linux/types.h>
 
 #include <media/media-device.h>
 #include <media/media-devnode.h>
 #include <media/media-entity.h>
 
+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(*media_device_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)
-- 
2.4.10


WARNING: multiple messages have this Message-ID (diff)
From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
To: linux-media@vger.kernel.org
Cc: linux-sh@vger.kernel.org
Subject: [PATCH/RFC 22/48] media: Add per-file-handle data support
Date: Thu, 17 Dec 2015 10:40:00 +0200	[thread overview]
Message-ID: <1450341626-6695-23-git-send-email-laurent.pinchart+renesas@ideasonboard.com> (raw)
In-Reply-To: <1450341626-6695-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com>

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 <laurent.pinchart+renesas@ideasonboard.com>
---
 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..285f7d79d848 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -24,23 +24,45 @@
 #include <linux/export.h>
 #include <linux/ioctl.h>
 #include <linux/media.h>
+#include <linux/slab.h>
 #include <linux/types.h>
 
 #include <media/media-device.h>
 #include <media/media-devnode.h>
 #include <media/media-entity.h>
 
+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(*media_device_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)
-- 
2.4.10


  parent reply	other threads:[~2015-12-17  8:40 UTC|newest]

Thread overview: 114+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-17  8:39 [PATCH/RFC 00/48] Request API and proof-of-concept implementation Laurent Pinchart
2015-12-17  8:39 ` Laurent Pinchart
2015-12-17  8:39 ` [PATCH/RFC 01/48] v4l: vsp1: Use pipeline display list to decide how to write to modules Laurent Pinchart
2015-12-17  8:39   ` Laurent Pinchart
2015-12-17  8:39 ` [PATCH/RFC 02/48] v4l: vsp1: Always setup the display list Laurent Pinchart
2015-12-17  8:39   ` Laurent Pinchart
2015-12-17  8:39 ` [PATCH/RFC 03/48] v4l: vsp1: Simplify frame end processing Laurent Pinchart
2015-12-17  8:39   ` Laurent Pinchart
2015-12-17  8:39 ` [PATCH/RFC 04/48] v4l: vsp1: Split display list manager from display list Laurent Pinchart
2015-12-17  8:39   ` Laurent Pinchart
2015-12-17  8:39 ` [PATCH/RFC 05/48] v4l: vsp1: Store the display list manager in the WPF Laurent Pinchart
2015-12-17  8:39   ` Laurent Pinchart
2015-12-17  8:39 ` [PATCH/RFC 06/48] v4l: vsp1: bru: Don't program background color in control set handler Laurent Pinchart
2015-12-17  8:39   ` Laurent Pinchart
2015-12-17  8:39 ` [PATCH/RFC 07/48] v4l: vsp1: rwpf: Don't program alpha value " Laurent Pinchart
2015-12-17  8:39   ` Laurent Pinchart
2015-12-17  8:39 ` [PATCH/RFC 08/48] v4l: vsp1: sru: Don't program intensity " Laurent Pinchart
2015-12-17  8:39   ` Laurent Pinchart
2015-12-17  8:39 ` [PATCH/RFC 09/48] v4l: vsp1: Don't setup control handler when starting streaming Laurent Pinchart
2015-12-17  8:39   ` Laurent Pinchart
2015-12-17  8:39 ` [PATCH/RFC 10/48] v4l: vsp1: Enable display list support for the HS[IT], LUT, SRU and UDS Laurent Pinchart
2015-12-17  8:39   ` Laurent Pinchart
2015-12-17  8:39 ` [PATCH/RFC 11/48] v4l: vsp1: Don't configure RPF memory buffers before calculating offsets Laurent Pinchart
2015-12-17  8:39   ` Laurent Pinchart
2015-12-17  8:39 ` [PATCH/RFC 12/48] v4l: vsp1: Remove unneeded entity streaming flag Laurent Pinchart
2015-12-17  8:39   ` Laurent Pinchart
2015-12-17  8:39 ` [PATCH/RFC 13/48] v4l: vsp1: Document calling context of vsp1_pipeline_propagate_alpha() Laurent Pinchart
2015-12-17  8:39   ` Laurent Pinchart
2015-12-17  8:39 ` [PATCH/RFC 14/48] v4l: vsp1: Fix 80 characters per line violations Laurent Pinchart
2015-12-17  8:39   ` Laurent Pinchart
2015-12-17  8:39 ` [PATCH/RFC 15/48] v4l: vsp1: Add header display list support Laurent Pinchart
2015-12-17  8:39   ` Laurent Pinchart
2015-12-17  8:39 ` [PATCH/RFC 16/48] v4l: vsp1: Use display lists with the userspace API Laurent Pinchart
2015-12-17  8:39   ` Laurent Pinchart
2015-12-17  8:39 ` [PATCH/RFC 17/48] v4l: vsp1: Move subdev initialization code to vsp1_entity_init() Laurent Pinchart
2015-12-17  8:39   ` Laurent Pinchart
2015-12-17  8:39 ` [PATCH/RFC 18/48] v4l: vsp1: Consolidate entity ops in a struct vsp1_entity_operations Laurent Pinchart
2015-12-17  8:39   ` Laurent Pinchart
2015-12-17  8:39 ` [PATCH/RFC 19/48] v4l: vsp1: Fix BRU try compose rectangle storage Laurent Pinchart
2015-12-17  8:39   ` Laurent Pinchart
2015-12-17  8:39 ` [PATCH/RFC 20/48] v4l: vsp1: Add race condition FIXME comment Laurent Pinchart
2015-12-17  8:39   ` Laurent Pinchart
2015-12-17  8:39 ` [PATCH/RFC 21/48] media: Move media_device link_notify operation to an ops structure Laurent Pinchart
2015-12-17  8:39   ` Laurent Pinchart
2015-12-18 22:24   ` Sakari Ailus
2015-12-18 22:24     ` Sakari Ailus
2015-12-17  8:40 ` Laurent Pinchart [this message]
2015-12-17  8:40   ` [PATCH/RFC 22/48] media: Add per-file-handle data support Laurent Pinchart
2015-12-19  0:40   ` Sakari Ailus
2015-12-19  0:40     ` Sakari Ailus
2015-12-17  8:40 ` [PATCH/RFC 23/48] media: Add request API Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 24/48] media: Add per-entity request data support Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 25/48] videodev2.h: Add request field to v4l2_buffer Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 26/48] videodev2.h: Add request field to v4l2_pix_format_mplane Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-18 11:18   ` Hans Verkuil
2015-12-18 11:18     ` Hans Verkuil
2015-12-18 17:16     ` Laurent Pinchart
2015-12-18 17:16       ` Laurent Pinchart
2015-12-18 17:37       ` Geert Uytterhoeven
2015-12-18 17:37         ` Geert Uytterhoeven
2015-12-21  3:53         ` Laurent Pinchart
2015-12-21  3:53           ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 27/48] v4l2-subdev.h: Add request field to format and selection structures Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-18 11:20   ` Hans Verkuil
2015-12-18 11:20     ` Hans Verkuil
2015-12-21  4:00     ` Laurent Pinchart
2015-12-21  4:00       ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 28/48] v4l: Support the request API in format operations Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 29/48] v4l: subdev: Add pad config allocator and init Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 30/48] v4l: subdev: Call pad init_cfg operation when opening subdevs Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 31/48] v4l: subdev: Support the request API in format and selection operations Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 32/48] vb2: Add allow_requests flag Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 33/48] vb2: Add helper function to check for request buffers Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 34/48] vb2: Add helper function to queue request-specific buffer Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 35/48] DocBook: media: Document the media request API Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 36/48] DocBook: media: Document the V4L2 " Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 37/48] DocBook: media: Document the subdev selection API Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 38/48] DocBook: media: Document the V4L2 subdev request API Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 39/48] v4l: vsp1: Implement and use the subdev pad::init_cfg configuration Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 40/48] v4l: vsp1: Store active formats in a pad config structure Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 41/48] v4l: vsp1: Store active selection rectangles " Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 42/48] v4l: vsp1: Create a new configure operation to setup modules Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 43/48] v4l: vsp1: Merge RPF and WPF pad ops structures Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 44/48] v4l: vsp1: Pass a media request to the module configure operations Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 45/48] v4l: vsp1: Use __vsp1_video_try_format to initialize format at init time Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 46/48] v4l: vsp1: Support video device formats stored in requests Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 47/48] v4l: vsp1: Pass display list explicitly to configure functions Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart
2015-12-17  8:40 ` [PATCH/RFC 48/48] v4l: vsp1: Support the request API Laurent Pinchart
2015-12-17  8:40   ` Laurent Pinchart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1450341626-6695-23-git-send-email-laurent.pinchart+renesas@ideasonboard.com \
    --to=laurent.pinchart+renesas@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.