[PATCH v3 7/8] media: core: export v4l2_translate_cmd

Ricardo Ribalda posted 8 patches 3 months, 1 week ago
There is a newer version of this series
[PATCH v3 7/8] media: core: export v4l2_translate_cmd
Posted by Ricardo Ribalda 3 months, 1 week ago
video_translate_cmd() can be useful for drivers to convert between the
VIDIOC_*32 and VIDIOC_ defines. Let's export it.

Now that the function is exported, use this opportunity to rename the
function with the v4l2_ prefix, that is less ambiguous than video_

The VIDIOC_*32 defines are not accessible by the drivers, they live in
v4l2-compat-ioctl32.c.

Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 5 +++--
 include/media/v4l2-ioctl.h           | 1 +
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index 650dc1956f73d2f1943b56c42140c7b8d757259f..1e22ca898ab77e581d78c1a618e1de0e57281cde 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -3245,7 +3245,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
 	return ret;
 }
 
-static unsigned int video_translate_cmd(unsigned int cmd)
+unsigned int v4l2_translate_cmd(unsigned int cmd)
 {
 #if !defined(CONFIG_64BIT) && defined(CONFIG_COMPAT_32BIT_TIME)
 	switch (cmd) {
@@ -3266,6 +3266,7 @@ static unsigned int video_translate_cmd(unsigned int cmd)
 
 	return cmd;
 }
+EXPORT_SYMBOL(v4l2_translate_cmd);
 
 static int video_get_user(void __user *arg, void *parg,
 			  unsigned int real_cmd, unsigned int cmd,
@@ -3426,7 +3427,7 @@ video_usercopy(struct file *file, unsigned int orig_cmd, unsigned long arg,
 	size_t  array_size = 0;
 	void __user *user_ptr = NULL;
 	void	**kernel_ptr = NULL;
-	unsigned int cmd = video_translate_cmd(orig_cmd);
+	unsigned int cmd = v4l2_translate_cmd(orig_cmd);
 	const size_t ioc_size = _IOC_SIZE(cmd);
 
 	/*  Copy arguments into temp kernel buffer  */
diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
index c6ec87e88dfef9e6cfe1d1fb587c1600882fb14d..82695c3a300a73219f262fb556ed61a8f09d273e 100644
--- a/include/media/v4l2-ioctl.h
+++ b/include/media/v4l2-ioctl.h
@@ -679,6 +679,7 @@ long int v4l2_compat_ioctl32(struct file *file, unsigned int cmd,
 #endif
 
 unsigned int v4l2_compat_translate_cmd(unsigned int cmd);
+unsigned int v4l2_translate_cmd(unsigned int cmd);
 int v4l2_compat_get_user(void __user *arg, void *parg, unsigned int cmd);
 int v4l2_compat_put_user(void __user *arg, void *parg, unsigned int cmd);
 int v4l2_compat_get_array_args(struct file *file, void *mbuf,

-- 
2.50.0.727.gbf7dc18ff4-goog
Re: [PATCH v3 7/8] media: core: export v4l2_translate_cmd
Posted by hans@jjverkuil.nl 3 months, 1 week ago
On 30/06/2025 16:20, Ricardo Ribalda wrote:
> video_translate_cmd() can be useful for drivers to convert between the
> VIDIOC_*32 and VIDIOC_ defines. Let's export it.
> 
> Now that the function is exported, use this opportunity to rename the
> function with the v4l2_ prefix, that is less ambiguous than video_
> 
> The VIDIOC_*32 defines are not accessible by the drivers, they live in
> v4l2-compat-ioctl32.c.
> 
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> ---
>  drivers/media/v4l2-core/v4l2-ioctl.c | 5 +++--
>  include/media/v4l2-ioctl.h           | 1 +
>  2 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
> index 650dc1956f73d2f1943b56c42140c7b8d757259f..1e22ca898ab77e581d78c1a618e1de0e57281cde 100644
> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
> @@ -3245,7 +3245,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
>  	return ret;
>  }
>  
> -static unsigned int video_translate_cmd(unsigned int cmd)
> +unsigned int v4l2_translate_cmd(unsigned int cmd)
>  {
>  #if !defined(CONFIG_64BIT) && defined(CONFIG_COMPAT_32BIT_TIME)
>  	switch (cmd) {
> @@ -3266,6 +3266,7 @@ static unsigned int video_translate_cmd(unsigned int cmd)
>  
>  	return cmd;
>  }
> +EXPORT_SYMBOL(v4l2_translate_cmd);

Please use EXPORT_SYMBOL_GPL.

With that change:

Reviewed-by: Hans Verkuil <hverkuil@xs4all.nl>

Regards,

	Hans

>  
>  static int video_get_user(void __user *arg, void *parg,
>  			  unsigned int real_cmd, unsigned int cmd,
> @@ -3426,7 +3427,7 @@ video_usercopy(struct file *file, unsigned int orig_cmd, unsigned long arg,
>  	size_t  array_size = 0;
>  	void __user *user_ptr = NULL;
>  	void	**kernel_ptr = NULL;
> -	unsigned int cmd = video_translate_cmd(orig_cmd);
> +	unsigned int cmd = v4l2_translate_cmd(orig_cmd);
>  	const size_t ioc_size = _IOC_SIZE(cmd);
>  
>  	/*  Copy arguments into temp kernel buffer  */
> diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
> index c6ec87e88dfef9e6cfe1d1fb587c1600882fb14d..82695c3a300a73219f262fb556ed61a8f09d273e 100644
> --- a/include/media/v4l2-ioctl.h
> +++ b/include/media/v4l2-ioctl.h
> @@ -679,6 +679,7 @@ long int v4l2_compat_ioctl32(struct file *file, unsigned int cmd,
>  #endif
>  
>  unsigned int v4l2_compat_translate_cmd(unsigned int cmd);
> +unsigned int v4l2_translate_cmd(unsigned int cmd);
>  int v4l2_compat_get_user(void __user *arg, void *parg, unsigned int cmd);
>  int v4l2_compat_put_user(void __user *arg, void *parg, unsigned int cmd);
>  int v4l2_compat_get_array_args(struct file *file, void *mbuf,
>