diff mbox series

[v3,5/8] media: v4l2-core: return -ENODEV from ioctl when not registered

Message ID 20210614103409.3154127-6-arnd@kernel.org
State New
Headers show
Series media: v4l2: compat ioctl fixes | expand

Commit Message

Arnd Bergmann June 14, 2021, 10:34 a.m. UTC
From: Arnd Bergmann <arnd@arndb.de>


I spotted a minor difference is handling of unregistered devices
between native and compat ioctls: the native handler never tries
to call into the driver if a device is not marked as registered.

I did not check whether this can cause issues in the kernel, or
just a different between return codes, but it clearly makes
sense that both should behave the same way.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>

---
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 3 +++
 1 file changed, 3 insertions(+)

-- 
2.29.2

Comments

Laurent Pinchart June 14, 2021, 5:04 p.m. UTC | #1
Hi Arnd,

Thank you for the patch.

On Mon, Jun 14, 2021 at 12:34:06PM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>

> 

> I spotted a minor difference is handling of unregistered devices

> between native and compat ioctls: the native handler never tries

> to call into the driver if a device is not marked as registered.

> 

> I did not check whether this can cause issues in the kernel, or

> just a different between return codes, but it clearly makes

> sense that both should behave the same way.

> 

> Signed-off-by: Arnd Bergmann <arnd@arndb.de>


Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>


> ---

>  drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 3 +++

>  1 file changed, 3 insertions(+)

> 

> diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c

> index 0ca75f6784c5..47aff3b19742 100644

> --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c

> +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c

> @@ -1244,6 +1244,9 @@ long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)

>  	if (!file->f_op->unlocked_ioctl)

>  		return ret;

>  

> +	if (!video_is_registered(vdev))

> +		return -ENODEV;

> +

>  	if (_IOC_TYPE(cmd) == 'V' && _IOC_NR(cmd) < BASE_VIDIOC_PRIVATE)

>  		ret = file->f_op->unlocked_ioctl(file, cmd,

>  					(unsigned long)compat_ptr(arg));


-- 
Regards,

Laurent Pinchart
Laurent Pinchart June 14, 2021, 5:04 p.m. UTC | #2
Hi Arnd,

Thank you for the patch.

On Mon, Jun 14, 2021 at 12:34:06PM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>

> 

> I spotted a minor difference is handling of unregistered devices

> between native and compat ioctls: the native handler never tries

> to call into the driver if a device is not marked as registered.

> 

> I did not check whether this can cause issues in the kernel, or

> just a different between return codes, but it clearly makes

> sense that both should behave the same way.

> 

> Signed-off-by: Arnd Bergmann <arnd@arndb.de>


Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>


> ---

>  drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 3 +++

>  1 file changed, 3 insertions(+)

> 

> diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c

> index 0ca75f6784c5..47aff3b19742 100644

> --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c

> +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c

> @@ -1244,6 +1244,9 @@ long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)

>  	if (!file->f_op->unlocked_ioctl)

>  		return ret;

>  

> +	if (!video_is_registered(vdev))

> +		return -ENODEV;

> +

>  	if (_IOC_TYPE(cmd) == 'V' && _IOC_NR(cmd) < BASE_VIDIOC_PRIVATE)

>  		ret = file->f_op->unlocked_ioctl(file, cmd,

>  					(unsigned long)compat_ptr(arg));


-- 
Regards,

Laurent Pinchart
diff mbox series

Patch

diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index 0ca75f6784c5..47aff3b19742 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -1244,6 +1244,9 @@  long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
 	if (!file->f_op->unlocked_ioctl)
 		return ret;
 
+	if (!video_is_registered(vdev))
+		return -ENODEV;
+
 	if (_IOC_TYPE(cmd) == 'V' && _IOC_NR(cmd) < BASE_VIDIOC_PRIVATE)
 		ret = file->f_op->unlocked_ioctl(file, cmd,
 					(unsigned long)compat_ptr(arg));