lkml.org 
[lkml]   [2019]   [May]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v4 1/2] media: v4l2-subdev: Verify arguments of v4l2_subdev_call()
Hi Janusz,

On Sat, May 11, 2019 at 12:10:30PM +0200, Janusz Krzysztofik wrote:
> Correctness of format type (try or active) and pad number parameters
> passed to subdevice operation callbacks is now verified only for IOCTL
> calls. However, those callbacks are also used by drivers, e.g., V4L2
> host interfaces.
>
> Since both subdev_do_ioctl() and drivers are using v4l2_subdev_call()
> macro while calling subdevice operations, move those parameter checks
> from subdev_do_ioctl() to v4l2_subdev_call() so we can avoid taking care
> of those checks inside drivers.

I have to say I really like this patch!

>
> Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
> ---
> drivers/media/v4l2-core/v4l2-subdev.c | 222 +++++++++++++++-----------
> include/media/v4l2-subdev.h | 6 +
> 2 files changed, 139 insertions(+), 89 deletions(-)
>
> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> index d75815ab0d7b..cd50fcb86c47 100644
> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> @@ -120,56 +120,165 @@ static int subdev_close(struct file *file)
> return 0;
> }
>
> +static inline int check_which(__u32 which)
> +{
> + return which != V4L2_SUBDEV_FORMAT_TRY &&
> + which != V4L2_SUBDEV_FORMAT_ACTIVE ? -EINVAL : 0;
> +}
> +
> #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
> +static inline int check_pad(struct v4l2_subdev *sd, __u32 pad)
> +{
> + return pad >= sd->entity.num_pads ? -EINVAL : 0;
> +}
> +#else
> +#define check_pad(...) 0

This should be an inline function as well. Or just have one function; the
prototype is the same anyway.

> +#endif
> +
> static int check_format(struct v4l2_subdev *sd,

inline?

> struct v4l2_subdev_format *format)
> {
> - if (format->which != V4L2_SUBDEV_FORMAT_TRY &&
> - format->which != V4L2_SUBDEV_FORMAT_ACTIVE)
> - return -EINVAL;
> + return check_which(format->which) ? : check_pad(sd, format->pad);
> +}

--
Kind regards,

Sakari Ailus
sakari.ailus@linux.intel.com

\
 
 \ /
  Last update: 2019-05-14 13:11    [W:1.405 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site