Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 7b6c1b4c0e1e ("usb: musb: fix runtime PM in debugfs")

Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
Cc: stable@vger.kernel.org
Signed-off-by: Bin Liu <b-liu@ti.com>
Link: https://lore.kernel.org/r/20200525025049.3400-7-b-liu@ti.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Dinghao Liu and committed by
Greg Kroah-Hartman
e4befc12 685f5f24

+5 -5
+5 -5
drivers/usb/musb/musb_debugfs.c
··· 168 168 u8 test; 169 169 char buf[24]; 170 170 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 + 171 176 pm_runtime_get_sync(musb->controller); 172 177 test = musb_readb(musb->mregs, MUSB_TESTMODE); 173 178 if (test) { ··· 180 175 "Please do USB Bus Reset to start a new test.\n"); 181 176 goto ret; 182 177 } 183 - 184 - memset(buf, 0x00, sizeof(buf)); 185 - 186 - if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) 187 - return -EFAULT; 188 178 189 179 if (strstarts(buf, "force host full-speed")) 190 180 test = MUSB_TEST_FORCE_HOST | MUSB_TEST_FORCE_FS;