Message ID | 20240610100530.1107771-26-sakari.ailus@linux.intel.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Media device lifetime management | expand |
On 10/06/2024 12:05, Sakari Ailus wrote: > A media devnode may be registered only once. Enforce this by setting the > minor to -1 in init. > > Registration initialises the character device and sets up the device name. > These should take place only once during the lifetime of the media device. This has nothing to do with patch 23/26, right? I would move this to before that patch. > > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Acked-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Regards, Hans > --- > drivers/media/mc/mc-devnode.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/media/mc/mc-devnode.c b/drivers/media/mc/mc-devnode.c > index 8cb4e0eec17f..758971f310c3 100644 > --- a/drivers/media/mc/mc-devnode.c > +++ b/drivers/media/mc/mc-devnode.c > @@ -240,6 +240,7 @@ void media_devnode_init(struct media_devnode *devnode) > { > device_initialize(&devnode->dev); > devnode->dev.release = media_devnode_release; > + devnode->minor = -1; > } > > int __must_check media_devnode_register(struct media_devnode *devnode, > @@ -251,6 +252,9 @@ int __must_check media_devnode_register(struct media_devnode *devnode, > int minor; > int ret; > > + if (devnode->minor != -1) > + return -EINVAL; > + > /* Part 1: Find a free minor number */ > mutex_lock(&media_devnode_lock); > minor = find_first_zero_bit(media_devnode_nums, MEDIA_NUM_DEVICES);
Hi Hans, On Mon, Jun 17, 2024 at 12:42:02PM +0200, Hans Verkuil wrote: > On 10/06/2024 12:05, Sakari Ailus wrote: > > A media devnode may be registered only once. Enforce this by setting the > > minor to -1 in init. > > > > Registration initialises the character device and sets up the device name. > > These should take place only once during the lifetime of the media device. > > This has nothing to do with patch 23/26, right? > > I would move this to before that patch. Sounds good. > > > > > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> > > Acked-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Thanks!
diff --git a/drivers/media/mc/mc-devnode.c b/drivers/media/mc/mc-devnode.c index 8cb4e0eec17f..758971f310c3 100644 --- a/drivers/media/mc/mc-devnode.c +++ b/drivers/media/mc/mc-devnode.c @@ -240,6 +240,7 @@ void media_devnode_init(struct media_devnode *devnode) { device_initialize(&devnode->dev); devnode->dev.release = media_devnode_release; + devnode->minor = -1; } int __must_check media_devnode_register(struct media_devnode *devnode, @@ -251,6 +252,9 @@ int __must_check media_devnode_register(struct media_devnode *devnode, int minor; int ret; + if (devnode->minor != -1) + return -EINVAL; + /* Part 1: Find a free minor number */ mutex_lock(&media_devnode_lock); minor = find_first_zero_bit(media_devnode_nums, MEDIA_NUM_DEVICES);
A media devnode may be registered only once. Enforce this by setting the minor to -1 in init. Registration initialises the character device and sets up the device name. These should take place only once during the lifetime of the media device. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> --- drivers/media/mc/mc-devnode.c | 4 ++++ 1 file changed, 4 insertions(+)