All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yang Yingliang <yangyingliang@huawei.com>
To: <linux-usb@vger.kernel.org>
Cc: <laurent.pinchart@ideasonboard.com>,
	<dan.scally@ideasonboard.com>, <gregkh@linuxfoundation.org>,
	<yangyingliang@huawei.com>
Subject: [PATCH -next v2] usb: gadget: uvc: fix missing mutex_unlock() if kstrtou8() fails
Date: Mon, 13 Feb 2023 15:09:26 +0800	[thread overview]
Message-ID: <20230213070926.776447-1-yangyingliang@huawei.com> (raw)

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(-)

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) {
-- 
2.25.1


             reply	other threads:[~2023-02-13  7:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-13  7:09 Yang Yingliang [this message]
2023-02-15 10:22 ` [PATCH -next v2] usb: gadget: uvc: fix missing mutex_unlock() if kstrtou8() fails Laurent Pinchart
2023-02-16 14:33 ` Dan Scally

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230213070926.776447-1-yangyingliang@huawei.com \
    --to=yangyingliang@huawei.com \
    --cc=dan.scally@ideasonboard.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.