Re: [PATCH] usb: gadget: uvc: fix changing interface name via configfs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Michael,

Thank you for the patch.

On Thu, Jul 07, 2022 at 01:56:12PM +0200, Michael Grzeschik wrote:
> When setting the function name, it is always truncated by one char since
> snprintf is always including the null-termination in the len parameter.
> We use strscpy and fix the size setting to use len + 1 instead.
> 
> Fixes: 324e4f85070f ("usb: gadget: uvc: allow changing interface name via configfs")
> Signed-off-by: Michael Grzeschik <m.grzeschik@xxxxxxxxxxxxxx>

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

> ---
>  drivers/usb/gadget/function/uvc_configfs.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c
> index e5a6b6e36b3dd8..4303a3283ba0a3 100644
> --- a/drivers/usb/gadget/function/uvc_configfs.c
> +++ b/drivers/usb/gadget/function/uvc_configfs.c
> @@ -2371,6 +2371,7 @@ static ssize_t f_uvc_opts_string_##cname##_store(struct config_item *item,\
>  					  const char *page, size_t len)	\
>  {									\
>  	struct f_uvc_opts *opts = to_f_uvc_opts(item);			\
> +	int size = min(sizeof(opts->aname), len + 1);			\

>  	int ret = 0;							\
>  									\
>  	mutex_lock(&opts->lock);					\
> @@ -2379,8 +2380,9 @@ static ssize_t f_uvc_opts_string_##cname##_store(struct config_item *item,\
>  		goto end;						\
>  	}								\
>  									\
> -	ret = snprintf(opts->aname, min(sizeof(opts->aname), len),	\
> -			"%s", page);					\
> +	ret = strscpy(opts->aname, page, size);				\
> +	if (ret == -E2BIG)						\
> +		ret = size - 1;						\
>  									\
>  end:									\
>  	mutex_unlock(&opts->lock);					\

-- 
Regards,

Laurent Pinchart



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux