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

staging: rtl8712: add error handler in r8712_usbctrl_vendorreq()

When 'status' returned from usb_control_msg() is not equal to 'len',
that usb_control_msg() is on partial failure, r8712_usbctrl_vendorreq()
will treat partial reads as success.

Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Wang Cheng <wanngchenng@gmail.com>
Link: https://lore.kernel.org/r/e33ea53d36c422fbe7eabec5bd9eecb0ebce1bc5.1652618244.git.wanngchenng@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Wang Cheng and committed by
Greg Kroah-Hartman
644ee3bf ea32366a

+14 -7
+14 -7
drivers/staging/rtl8712/usb_ops_linux.c
··· 495 495 } 496 496 status = usb_control_msg(udev, pipe, request, reqtype, value, index, 497 497 pIo_buf, len, 500); 498 - if (status > 0) { /* Success this control transfer. */ 499 - if (requesttype == 0x01) { 500 - /* For Control read transfer, we have to copy the read 501 - * data from pIo_buf to pdata. 502 - */ 503 - memcpy(pdata, pIo_buf, status); 504 - } 498 + if (status < 0) 499 + goto free; 500 + if (status != len) { 501 + status = -EREMOTEIO; 502 + goto free; 505 503 } 504 + /* Success this control transfer. */ 505 + if (requesttype == 0x01) { 506 + /* For Control read transfer, we have to copy the read 507 + * data from pIo_buf to pdata. 508 + */ 509 + memcpy(pdata, pIo_buf, status); 510 + } 511 + 512 + free: 506 513 kfree(palloc_buf); 507 514 return status; 508 515 }