Skip to content

Commit

Permalink
usb: gadget: uvc: fix missing mutex_unlock() if kstrtou8() fails
Browse files Browse the repository at this point in the history
If kstrtou8() fails, the mutex_unlock() is missed, move kstrtou8()
before mutex_lock() to fix it up.

Fixes: 0525210 ("usb: gadget: uvc: Allow definition of XUs in configfs")
Fixes: b3c839b ("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>
  • Loading branch information
Yang Yingliang authored and Greg Kroah-Hartman committed Feb 14, 2023
1 parent 77191db commit 7ebb605
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions drivers/usb/gadget/function/uvc_configfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,17 +590,17 @@ 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->
ci_parent->ci_parent;
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);
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 7ebb605

Please sign in to comment.