Skip to content

Commit e4befc1

Browse files
dinghaoliugregkh
authored andcommitted
usb: musb: Fix runtime PM imbalance on error
When copy_from_user() returns an error code, there is a runtime PM usage counter imbalance. Fix this by moving copy_from_user() to the beginning of this function. Fixes: 7b6c1b4 ("usb: musb: fix runtime PM in debugfs") Signed-off-by: Dinghao Liu <[email protected]> Cc: [email protected] Signed-off-by: Bin Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 685f5f2 commit e4befc1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

drivers/usb/musb/musb_debugfs.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ static ssize_t musb_test_mode_write(struct file *file,
168168
u8 test;
169169
char buf[24];
170170

171+
memset(buf, 0x00, sizeof(buf));
172+
173+
if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
174+
return -EFAULT;
175+
171176
pm_runtime_get_sync(musb->controller);
172177
test = musb_readb(musb->mregs, MUSB_TESTMODE);
173178
if (test) {
@@ -176,11 +181,6 @@ static ssize_t musb_test_mode_write(struct file *file,
176181
goto ret;
177182
}
178183

179-
memset(buf, 0x00, sizeof(buf));
180-
181-
if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
182-
return -EFAULT;
183-
184184
if (strstarts(buf, "force host full-speed"))
185185
test = MUSB_TEST_FORCE_HOST | MUSB_TEST_FORCE_FS;
186186

0 commit comments

Comments
 (0)