All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: Jacopo Mondi <jacopo@jmondi.org>
Cc: Andrey Konovalov <andrey.konovalov@linaro.org>,
	linux-media@vger.kernel.org, libcamera-devel@lists.libcamera.org,
	hverkuil-cisco@xs4all.nl, mchehab@kernel.org
Subject: Re: [libcamera-devel] [PATCH 2/4] media: v4l2-dev: Add v4l2_device_register_ro_subdev_node()
Date: Thu, 26 Mar 2020 02:08:08 +0200	[thread overview]
Message-ID: <20200326000808.GB3709@mara.localdomain> (raw)
In-Reply-To: <20200325112342.andqi2uognizd4uq@uno.localdomain>

Hi Jacopo,

On Wed, Mar 25, 2020 at 12:23:42PM +0100, Jacopo Mondi wrote:
> Hi Andrey,
>    thanks for the review
> 
> On Wed, Mar 25, 2020 at 11:42:27AM +0300, Andrey Konovalov wrote:
> > Hi Jacopo,
> >
> > Thank you for your patch set!
> >
> > On 24.03.2020 23:28, Jacopo Mondi wrote:
> > > Add to the V4L2 code a function to register device nodes for video
> > > subdevices in read-only mode.
> > >
> > > Registering a device node in read-only mode is useful to expose to
> > > userspace the current sub-device configuration, without allowing
> > > application to change it by using the V4L2 subdevice ioctls.
> > >
> > > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> > > ---
> > >   drivers/media/v4l2-core/v4l2-device.c | 16 +++++++++++++++-
> > >   drivers/media/v4l2-core/v4l2-subdev.c | 19 +++++++++++++++++++
> > >   include/media/v4l2-dev.h              |  7 +++++++
> > >   include/media/v4l2-device.h           | 10 ++++++++++
> > >   4 files changed, 51 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
> > > index 63d6b147b21e..6f9dba36eda1 100644
> > > --- a/drivers/media/v4l2-core/v4l2-device.c
> > > +++ b/drivers/media/v4l2-core/v4l2-device.c
> > > @@ -188,7 +188,8 @@ static void v4l2_device_release_subdev_node(struct video_device *vdev)
> > >   	kfree(vdev);
> > >   }
> > > -int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
> > > +int __v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev,
> > > +					bool read_only)
> > >   {
> > >   	struct video_device *vdev;
> > >   	struct v4l2_subdev *sd;
> > > @@ -217,6 +218,8 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
> > >   		vdev->fops = &v4l2_subdev_fops;
> > >   		vdev->release = v4l2_device_release_subdev_node;
> > >   		vdev->ctrl_handler = sd->ctrl_handler;
> > > +		if (read_only)
> > > +			vdev->flags |= V4L2_FL_RO_DEVNODE;
> >
> > <snip>
> >
> > > @@ -331,6 +331,7 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
> > >   	struct v4l2_fh *vfh = file->private_data;
> > >   #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
> > >   	struct v4l2_subdev_fh *subdev_fh = to_v4l2_subdev_fh(vfh);
> > > +	bool ro_devnode = !!(vdev->flags & V4L2_FL_RO_DEVNODE);

No need to shout, i.e.

	bool ro_devnode = ... & ...;

> >
> > So V4L2_FL_RO_DEVNODE is a bit mask, ...
> >
> > <snip>
> >
> > > diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
> > > index 48531e57cc5a..029873a338f2 100644
> > > --- a/include/media/v4l2-dev.h
> > > +++ b/include/media/v4l2-dev.h
> > > @@ -82,11 +82,18 @@ struct v4l2_ctrl_handler;
> > >    *	but the old crop API will still work as expected in order to preserve
> > >    *	backwards compatibility.
> > >    *	Never set this flag for new drivers.
> > > + * @V4L2_FL_RO_DEVNODE:
> > > + *	indicates that the video device node is registered in read-only mode.
> > > + *	The flag only applies to device nodes registered for sub-devices, it is
> > > + *	set by the core when the sub-devices device nodes are registered with
> > > + *	v4l2_device_register_ro_subdev_nodes() and used by the sub-device ioctl
> > > + *	handler to restrict access to some ioctl calls.
> > >    */
> > >   enum v4l2_video_device_flags {
> > >   	V4L2_FL_REGISTERED		= 0,
> > >   	V4L2_FL_USES_V4L2_FH		= 1,
> > >   	V4L2_FL_QUIRK_INVERTED_CROP	= 2,
> > > +	V4L2_FL_RO_DEVNODE		= 3,
> >
> > ... then V4L2_FL_RO_DEVNODE should rather be equal to 4, than to (V4L2_FL_USES_V4L2_FH | V4L2_FL_QUIRK_INVERTED_CROP)
> 
> Ups!
> 
> I should have noticed looking at V4L2_FL_REGISTERED=0 that these
> flags are actually meant to be used as bit shifts. I can't say I like
> the idea, but I should have known better than this.
> 
> I'll resend using set_bit() and test_bit().

You can also use BIT(flag name).

Either works, but IMO test_bit() is a bit of overkill.

-- 
Sakari Ailus

  reply	other threads:[~2020-03-26  0:08 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-24 20:28 [PATCH 0/4] media: Register read-only sub-dev devnode Jacopo Mondi
2020-03-24 20:28 ` [PATCH 1/4] Documentation: media: Document read-only subdevice Jacopo Mondi
2020-03-25 21:37   ` [libcamera-devel] " Laurent Pinchart
2020-03-25 22:38     ` Laurent Pinchart
2020-03-24 20:28 ` [PATCH 2/4] media: v4l2-dev: Add v4l2_device_register_ro_subdev_node() Jacopo Mondi
2020-03-25  8:42   ` [libcamera-devel] " Andrey Konovalov
2020-03-25 11:23     ` Jacopo Mondi
2020-03-26  0:08       ` Sakari Ailus [this message]
2020-03-25 21:45   ` Laurent Pinchart
2020-03-25 22:57     ` Jacopo Mondi
2020-03-24 20:28 ` [PATCH 3/4] media: bcm2835: Register sensor devnode as read-only Jacopo Mondi
2020-03-24 20:28 ` [PATCH 4/4] media: bcm2835: Fix trivial whitespace error Jacopo Mondi
2020-03-24 20:46   ` [libcamera-devel] " Laurent Pinchart
2020-03-24 22:25 ` [libcamera-devel] [PATCH 0/4] media: Register read-only sub-dev devnode Dave Stevenson
2020-03-24 23:37   ` Jacopo Mondi

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=20200326000808.GB3709@mara.localdomain \
    --to=sakari.ailus@linux.intel.com \
    --cc=andrey.konovalov@linaro.org \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=jacopo@jmondi.org \
    --cc=libcamera-devel@lists.libcamera.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@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.