Skip to contentSkip to conversation

USB: serial: iuu_phoenix: Use pseudorandom for xmas mode

RFC PATCH In review George Spelvin 1 participant 1 message Mar 28, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 35/50 USB: serial: iuu_phoenix: Use pseudorandom for xmas mode

I also fixed a couple of buffer overrun bugs in iuu_led_activity_on, based on code not expecting the "*buf_ptr++" to have been incremented.

- In xmas mode, the final setting of the period byte to 1 was done to buf_ptr[7], which was past the end of the buffer.
- In non-xmas mode, iuu_rgbf_fill_buffer() fills in 8 bytes starting with the IUU_SET_LED command. The net result is duplicating the command and writing an extra byte off the end of the buffer.

I rewrote the code to omit the ++, which is more legible.

Not tested because I don't have the hardware, but I don't think this code has been exercised much anyway.

---
 drivers/usb/serial/iuu_phoenix.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/usb/serial/iuu_phoenix.c +4 -3
index d5bff69b1769b..7aeea7b5ba8db 100644
@@ -353,10 +353,11 @@ static void iuu_led_activity_on(struct urb *urb)
 	struct usb_serial_port *port = urb->context;
 	int result;
 	char *buf_ptr = port->write_urb->transfer_buffer;
-	*buf_ptr++ = IUU_SET_LED;
+
 	if (xmas) {
-		get_random_bytes(buf_ptr, 6);
-		*(buf_ptr+7) = 1;
+		buf_ptr[0] = IUU_SET_LED;
+		prandom_bytes(buf_ptr+1, 6);
+		buf_ptr[7] = 1;
 	} else {
 		iuu_rgbf_fill_buffer(buf_ptr, 255, 255, 0, 0, 0, 0, 255);
 	}
Signature · 1 line
2.26.0