Skip to contentSkip to conversation

usb: host: xhci-dbgtty: fix check in dbc_tty_write()

PATCH New Sergey Shtylyov 1 participant 1 message Mar 2, 2022

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

PATCH 1/1 usb: host: xhci-dbgtty: fix check in dbc_tty_write()

The 'int count' parameter of the tty write() method gets assigned to *unsigned long* local variable in the fifo_in() macro which implies a problematic type cast. Fix the 'count' check before the fifo_in() invocation to account for the signed type of the 'count' parameter...

Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool.

---
 drivers/usb/host/xhci-dbgtty.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/host/xhci-dbgtty.c +1 -1
Index: usb/drivers/usb/host/xhci-dbgtty.c
===================================================================
@@ -216,7 +216,7 @@ static int dbc_tty_write(struct tty_stru
 	unsigned long		flags;
 
 	spin_lock_irqsave(&port->port_lock, flags);
-	if (count)
+	if (count > 0)
 		count = kfifo_in(&port->write_fifo, buf, count);
 	dbc_start_tx(port);
 	spin_unlock_irqrestore(&port->port_lock, flags);