diff mbox series

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

Message ID 20230210071718.4072995-1-yangyingliang@huawei.com (mailing list archive)
State Superseded
Headers show
Series [-next] usb: gadget: uvc: fix missing mutex_unlock() if kstrtou8() fails | expand

Commit Message

Yang Yingliang Feb. 10, 2023, 7:17 a.m. UTC
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@huawei.com>
---
 drivers/usb/gadget/function/uvc_configfs.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Comments

Laurent Pinchart Feb. 10, 2023, 10:36 a.m. UTC | #1
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@huawei.com>
> ---
>  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);
>
diff mbox series

Patch

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;
+	}
 
 	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);