Skip to content

Commit f53a7ad

Browse files
Prashant Malanidavem330
authored andcommitted
r8152: Set memory to all 0xFFs on failed reg reads
get_registers() blindly copies the memory written to by the usb_control_msg() call even if the underlying urb failed. This could lead to junk register values being read by the driver, since some indirect callers of get_registers() ignore the return values. One example is: ocp_read_dword() ignores the return value of generic_ocp_read(), which calls get_registers(). So, emulate PCI "Master Abort" behavior by setting the buffer to all 0xFFs when usb_control_msg() fails. This patch is copied from the r8152 driver (v2.12.0) published by Realtek (www.realtek.com). Signed-off-by: Prashant Malani <[email protected]> Acked-by: Hayes Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7177895 commit f53a7ad

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/net/usb/r8152.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,11 @@ int get_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data)
799799
ret = usb_control_msg(tp->udev, usb_rcvctrlpipe(tp->udev, 0),
800800
RTL8152_REQ_GET_REGS, RTL8152_REQT_READ,
801801
value, index, tmp, size, 500);
802+
if (ret < 0)
803+
memset(data, 0xff, size);
804+
else
805+
memcpy(data, tmp, size);
802806

803-
memcpy(data, tmp, size);
804807
kfree(tmp);
805808

806809
return ret;

0 commit comments

Comments
 (0)