diff mbox series

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

Message ID 20230213070926.776447-1-yangyingliang@huawei.com
State New
Headers show
Series [-next,v2] usb: gadget: uvc: fix missing mutex_unlock() if kstrtou8() fails | expand

Commit Message

Yang Yingliang Feb. 13, 2023, 7:09 a.m. UTC
If kstrtou8() fails, the mutex_unlock() is missed, move kstrtou8()
before mutex_lock() to fix it up.

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>
---
v1 -> v2:
  Move kstrtou8 before mutex_lock().
---
 drivers/usb/gadget/function/uvc_configfs.c | 32 +++++++++++-----------
 1 file changed, 16 insertions(+), 16 deletions(-)

Comments

Laurent Pinchart Feb. 15, 2023, 10:22 a.m. UTC | #1
Hi Yang,

Thank you for the patch.

On Mon, Feb 13, 2023 at 03:09:26PM +0800, Yang Yingliang wrote:
> If kstrtou8() fails, the mutex_unlock() is missed, move kstrtou8()
> before mutex_lock() to fix it up.
> 
> 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>

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

> ---
> v1 -> v2:
>   Move kstrtou8 before mutex_lock().
> ---
>  drivers/usb/gadget/function/uvc_configfs.c | 32 +++++++++++-----------
>  1 file changed, 16 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c
> index 18c6a1461b7e..62b759bb7613 100644
> --- a/drivers/usb/gadget/function/uvc_configfs.c
> +++ b/drivers/usb/gadget/function/uvc_configfs.c
> @@ -590,6 +590,10 @@ static ssize_t uvcg_default_output_b_source_id_store(struct config_item *item,
>  	int result;
>  	u8 num;
>  
> +	result = kstrtou8(page, 0, &num);
> +	if (result)
> +		return result;
> +
>  	mutex_lock(su_mutex); /* for navigating configfs hierarchy */
>  
>  	opts_item = group->cg_item.ci_parent->ci_parent->
> @@ -597,10 +601,6 @@ static ssize_t uvcg_default_output_b_source_id_store(struct config_item *item,
>  	opts = to_f_uvc_opts(opts_item);
>  	cd = &opts->uvc_output_terminal;
>  
> -	result = kstrtou8(page, 0, &num);
> -	if (result)
> -		return result;
> -
>  	mutex_lock(&opts->lock);
>  	cd->bSourceID = num;
>  	mutex_unlock(&opts->lock);
> @@ -707,15 +707,15 @@ static ssize_t uvcg_extension_b_num_controls_store(struct config_item *item,
>  	int ret;
>  	u8 num;
>  
> +	ret = kstrtou8(page, 0, &num);
> +	if (ret)
> +		return ret;
> +
>  	mutex_lock(su_mutex);
>  
>  	opts_item = item->ci_parent->ci_parent->ci_parent;
>  	opts = to_f_uvc_opts(opts_item);
>  
> -	ret = kstrtou8(page, 0, &num);
> -	if (ret)
> -		return ret;
> -
>  	mutex_lock(&opts->lock);
>  	xu->desc.bNumControls = num;
>  	mutex_unlock(&opts->lock);
> @@ -742,15 +742,15 @@ static ssize_t uvcg_extension_b_nr_in_pins_store(struct config_item *item,
>  	int ret;
>  	u8 num;
>  
> +	ret = kstrtou8(page, 0, &num);
> +	if (ret)
> +		return ret;
> +
>  	mutex_lock(su_mutex);
>  
>  	opts_item = item->ci_parent->ci_parent->ci_parent;
>  	opts = to_f_uvc_opts(opts_item);
>  
> -	ret = kstrtou8(page, 0, &num);
> -	if (ret)
> -		return ret;
> -
>  	mutex_lock(&opts->lock);
>  
>  	if (num == xu->desc.bNrInPins) {
> @@ -795,15 +795,15 @@ static ssize_t uvcg_extension_b_control_size_store(struct config_item *item,
>  	int ret;
>  	u8 num;
>  
> +	ret = kstrtou8(page, 0, &num);
> +	if (ret)
> +		return ret;
> +
>  	mutex_lock(su_mutex);
>  
>  	opts_item = item->ci_parent->ci_parent->ci_parent;
>  	opts = to_f_uvc_opts(opts_item);
>  
> -	ret = kstrtou8(page, 0, &num);
> -	if (ret)
> -		return ret;
> -
>  	mutex_lock(&opts->lock);
>  
>  	if (num == xu->desc.bControlSize) {
Daniel Scally Feb. 16, 2023, 2:33 p.m. UTC | #2
Hi Yang, thank you for catching the error.

On 13/02/2023 07:09, Yang Yingliang wrote:
> If kstrtou8() fails, the mutex_unlock() is missed, move kstrtou8()
> before mutex_lock() to fix it up.
>
> 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>


Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>

> ---
> v1 -> v2:
>    Move kstrtou8 before mutex_lock().
> ---
>   drivers/usb/gadget/function/uvc_configfs.c | 32 +++++++++++-----------
>   1 file changed, 16 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c
> index 18c6a1461b7e..62b759bb7613 100644
> --- a/drivers/usb/gadget/function/uvc_configfs.c
> +++ b/drivers/usb/gadget/function/uvc_configfs.c
> @@ -590,6 +590,10 @@ static ssize_t uvcg_default_output_b_source_id_store(struct config_item *item,
>   	int result;
>   	u8 num;
>   
> +	result = kstrtou8(page, 0, &num);
> +	if (result)
> +		return result;
> +
>   	mutex_lock(su_mutex); /* for navigating configfs hierarchy */
>   
>   	opts_item = group->cg_item.ci_parent->ci_parent->
> @@ -597,10 +601,6 @@ static ssize_t uvcg_default_output_b_source_id_store(struct config_item *item,
>   	opts = to_f_uvc_opts(opts_item);
>   	cd = &opts->uvc_output_terminal;
>   
> -	result = kstrtou8(page, 0, &num);
> -	if (result)
> -		return result;
> -
>   	mutex_lock(&opts->lock);
>   	cd->bSourceID = num;
>   	mutex_unlock(&opts->lock);
> @@ -707,15 +707,15 @@ static ssize_t uvcg_extension_b_num_controls_store(struct config_item *item,
>   	int ret;
>   	u8 num;
>   
> +	ret = kstrtou8(page, 0, &num);
> +	if (ret)
> +		return ret;
> +
>   	mutex_lock(su_mutex);
>   
>   	opts_item = item->ci_parent->ci_parent->ci_parent;
>   	opts = to_f_uvc_opts(opts_item);
>   
> -	ret = kstrtou8(page, 0, &num);
> -	if (ret)
> -		return ret;
> -
>   	mutex_lock(&opts->lock);
>   	xu->desc.bNumControls = num;
>   	mutex_unlock(&opts->lock);
> @@ -742,15 +742,15 @@ static ssize_t uvcg_extension_b_nr_in_pins_store(struct config_item *item,
>   	int ret;
>   	u8 num;
>   
> +	ret = kstrtou8(page, 0, &num);
> +	if (ret)
> +		return ret;
> +
>   	mutex_lock(su_mutex);
>   
>   	opts_item = item->ci_parent->ci_parent->ci_parent;
>   	opts = to_f_uvc_opts(opts_item);
>   
> -	ret = kstrtou8(page, 0, &num);
> -	if (ret)
> -		return ret;
> -
>   	mutex_lock(&opts->lock);
>   
>   	if (num == xu->desc.bNrInPins) {
> @@ -795,15 +795,15 @@ static ssize_t uvcg_extension_b_control_size_store(struct config_item *item,
>   	int ret;
>   	u8 num;
>   
> +	ret = kstrtou8(page, 0, &num);
> +	if (ret)
> +		return ret;
> +
>   	mutex_lock(su_mutex);
>   
>   	opts_item = item->ci_parent->ci_parent->ci_parent;
>   	opts = to_f_uvc_opts(opts_item);
>   
> -	ret = kstrtou8(page, 0, &num);
> -	if (ret)
> -		return ret;
> -
>   	mutex_lock(&opts->lock);
>   
>   	if (num == xu->desc.bControlSize) {
diff mbox series

Patch

diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c
index 18c6a1461b7e..62b759bb7613 100644
--- a/drivers/usb/gadget/function/uvc_configfs.c
+++ b/drivers/usb/gadget/function/uvc_configfs.c
@@ -590,6 +590,10 @@  static ssize_t uvcg_default_output_b_source_id_store(struct config_item *item,
 	int result;
 	u8 num;
 
+	result = kstrtou8(page, 0, &num);
+	if (result)
+		return result;
+
 	mutex_lock(su_mutex); /* for navigating configfs hierarchy */
 
 	opts_item = group->cg_item.ci_parent->ci_parent->
@@ -597,10 +601,6 @@  static ssize_t uvcg_default_output_b_source_id_store(struct config_item *item,
 	opts = to_f_uvc_opts(opts_item);
 	cd = &opts->uvc_output_terminal;
 
-	result = kstrtou8(page, 0, &num);
-	if (result)
-		return result;
-
 	mutex_lock(&opts->lock);
 	cd->bSourceID = num;
 	mutex_unlock(&opts->lock);
@@ -707,15 +707,15 @@  static ssize_t uvcg_extension_b_num_controls_store(struct config_item *item,
 	int ret;
 	u8 num;
 
+	ret = kstrtou8(page, 0, &num);
+	if (ret)
+		return ret;
+
 	mutex_lock(su_mutex);
 
 	opts_item = item->ci_parent->ci_parent->ci_parent;
 	opts = to_f_uvc_opts(opts_item);
 
-	ret = kstrtou8(page, 0, &num);
-	if (ret)
-		return ret;
-
 	mutex_lock(&opts->lock);
 	xu->desc.bNumControls = num;
 	mutex_unlock(&opts->lock);
@@ -742,15 +742,15 @@  static ssize_t uvcg_extension_b_nr_in_pins_store(struct config_item *item,
 	int ret;
 	u8 num;
 
+	ret = kstrtou8(page, 0, &num);
+	if (ret)
+		return ret;
+
 	mutex_lock(su_mutex);
 
 	opts_item = item->ci_parent->ci_parent->ci_parent;
 	opts = to_f_uvc_opts(opts_item);
 
-	ret = kstrtou8(page, 0, &num);
-	if (ret)
-		return ret;
-
 	mutex_lock(&opts->lock);
 
 	if (num == xu->desc.bNrInPins) {
@@ -795,15 +795,15 @@  static ssize_t uvcg_extension_b_control_size_store(struct config_item *item,
 	int ret;
 	u8 num;
 
+	ret = kstrtou8(page, 0, &num);
+	if (ret)
+		return ret;
+
 	mutex_lock(su_mutex);
 
 	opts_item = item->ci_parent->ci_parent->ci_parent;
 	opts = to_f_uvc_opts(opts_item);
 
-	ret = kstrtou8(page, 0, &num);
-	if (ret)
-		return ret;
-
 	mutex_lock(&opts->lock);
 
 	if (num == xu->desc.bControlSize) {