Re: [PATCH -next] usb: gadget: uvc: fix missing mutex_unlock() if kstrtou8() fails

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

 



Hi Yang,

Thank you for the patch.

On Fri, Feb 10, 2023 at 03:17:18PM +0800, Yang Yingliang wrote:
> Add missing mutex_unlock() if kstrtou8() fails in store functions.
> 
> Fixes: 0525210c9840 ("usb: gadget: uvc: Allow definition of XUs in configfs")
> Fixes: b3c839bd8a07 ("usb: gadget: uvc: Make bSourceID read/write")
> Signed-off-by: Yang Yingliang <yangyingliang@xxxxxxxxxx>
> ---
>  drivers/usb/gadget/function/uvc_configfs.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c
> index 18c6a1461b7e..c2f0eb1c1f87 100644
> --- a/drivers/usb/gadget/function/uvc_configfs.c
> +++ b/drivers/usb/gadget/function/uvc_configfs.c
> @@ -598,8 +598,10 @@ static ssize_t uvcg_default_output_b_source_id_store(struct config_item *item,
>  	cd = &opts->uvc_output_terminal;
>  
>  	result = kstrtou8(page, 0, &num);
> -	if (result)
> +	if (result) {
> +		mutex_unlock(su_mutex);
>  		return result;
> +	}

A better fix would, I think, be to move the kstrtou8() call before
locking any mutex. It doesn't need to be protected by a lock.

Same below.

>  
>  	mutex_lock(&opts->lock);
>  	cd->bSourceID = num;
> @@ -713,8 +715,10 @@ static ssize_t uvcg_extension_b_num_controls_store(struct config_item *item,
>  	opts = to_f_uvc_opts(opts_item);
>  
>  	ret = kstrtou8(page, 0, &num);
> -	if (ret)
> +	if (ret) {
> +		mutex_unlock(su_mutex);
>  		return ret;
> +	}
>  
>  	mutex_lock(&opts->lock);
>  	xu->desc.bNumControls = num;
> @@ -748,8 +752,10 @@ static ssize_t uvcg_extension_b_nr_in_pins_store(struct config_item *item,
>  	opts = to_f_uvc_opts(opts_item);
>  
>  	ret = kstrtou8(page, 0, &num);
> -	if (ret)
> +	if (ret) {
> +		mutex_unlock(su_mutex);
>  		return ret;
> +	}
>  
>  	mutex_lock(&opts->lock);
>  
> @@ -801,8 +807,10 @@ static ssize_t uvcg_extension_b_control_size_store(struct config_item *item,
>  	opts = to_f_uvc_opts(opts_item);
>  
>  	ret = kstrtou8(page, 0, &num);
> -	if (ret)
> +	if (ret) {
> +		mutex_unlock(su_mutex);
>  		return ret;
> +	}
>  
>  	mutex_lock(&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