]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
usb: gadget: uvc: fix missing mutex_unlock() if kstrtou8() fails
authorYang Yingliang <yangyingliang@huawei.com>
Mon, 13 Feb 2023 07:09:26 +0000 (15:09 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 11 Mar 2023 12:50:49 +0000 (13:50 +0100)
commit 7ebb605d2283fb2647b4fa82030307ce00bee436 upstream.

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>
Link: https://lore.kernel.org/r/20230213070926.776447-1-yangyingliang@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/function/uvc_configfs.c

index 0a3095c0450bbe428f26fd650b269bcf9ac3a164..1460142fbc4294a7a0975990079b0f938a1e5fa5 100644 (file)
@@ -524,6 +524,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->
@@ -531,10 +535,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);