Skip to contentSkip to conversation

serial: Don't assume uart_ops .throttle is always set

RFC PATCH In review Ilpo Järvinen 3 participants 4 messages Apr 28, 2022 – Apr 29, 2022 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 serial: Don't assume uart_ops .throttle is always set

uart_throttle() assumes that a driver provides a throttle function in uart_ops. But not all drivers do and there seems to nothing in serial_core that would set it either. Thus, check it before calling.

---
 drivers/tty/serial/serial_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/tty/serial/serial_core.c +2 -1
index 6a8963caf954..18c9d46e0b85 100644
@@ -697,7 +697,8 @@ static void uart_throttle(struct tty_struct *tty)
 		mask |= UPSTAT_AUTORTS;
 
 	if (port->status & mask) {
-		port->ops->throttle(port);
+		if (port->ops->throttle)
+			port->ops->throttle(port);
 		mask &= ~port->status;
 	}
 
Signature · 1 line
tg: (19317433057d..) serial/fix-uart_throttle (depends on: tty-linus)
#1 lore raw
Quoted 17 lines · Ilpo Järvinen

uart_throttle() assumes that a driver provides a throttle function in uart_ops. But not all drivers do and there seems to nothing in serial_core that would set it either. Thus, check it before calling.

---
 drivers/tty/serial/serial_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/tty/serial/serial_core.c +0 -0
index 6a8963caf954..18c9d46e0b85 100644

drivers/tty/serial/serial_core.c static void uart_throttle(struct tty_struct *tty) · line 704

Quoted 9 lines
drivers/tty/serial/serial_core.c +2 -1
@@ -697,7 +697,8 @@ static void uart_throttle(struct tty_struct *tty)
 		mask |= UPSTAT_AUTORTS;
 
 	if (port->status & mask) {
-		port->ops->throttle(port);
+		if (port->ops->throttle)
+			port->ops->throttle(port);
 		mask &= ~port->status;
 	}
 

What commit id does this "fix"?

thanks,

greg k-h

#2 lore raw
In reply to Ilpo Järvinen
Quoted 3 lines · Ilpo Järvinen

uart_throttle() assumes that a driver provides a throttle function in uart_ops. But not all drivers do and there seems to nothing in serial_core that would set it either. Thus, check it before calling.

If the driver does not provide throttle function, it should not set UPSTAT_AUTORTS nor UPSTAT_AUTOXOFF in port->status.

drivers/tty/serial/serial_core.c static void uart_throttle(struct tty_struct *tty) · line 699

Quoted 9 lines
drivers/tty/serial/serial_core.c +0 -0
index 6a8963caf954..18c9d46e0b85 100644
@@ -697,7 +697,8 @@ static void uart_throttle(struct tty_struct *tty)
 		mask |= UPSTAT_AUTORTS;
 
 	if (port->status & mask) {

This if condition is always false if driver did not set UPSTAT_AUTORTS nor UPSTAT_AUTOXOFF in port->status.

drivers/tty/serial/serial_core.c static void uart_throttle(struct tty_struct *tty) · line 704

Quoted 6 lines
drivers/tty/serial/serial_core.c +2 -1
-		port->ops->throttle(port);
+		if (port->ops->throttle)
+			port->ops->throttle(port);
 		mask &= ~port->status;
 	}
 

I think this patch is incorrect. The assumption is not ".throttle is always set" but rather ".throttle is set when UPSTAT_AUTORTS or UPSTAT_AUTOXOFF is set".

Best Regards,
Tomasz Mon

#3 lore raw
Quoted 21 lines · Tomasz Mon
Quoted 3 lines · Ilpo Järvinen

uart_throttle() assumes that a driver provides a throttle function in uart_ops. But not all drivers do and there seems to nothing in serial_core that would set it either. Thus, check it before calling.

If the driver does not provide throttle function, it should not set UPSTAT_AUTORTS nor UPSTAT_AUTOXOFF in port->status.

drivers/tty/serial/serial_core.c static void uart_throttle(struct tty_struct *tty) · line 699

Quoted 9 lines
drivers/tty/serial/serial_core.c +0 -0
index 6a8963caf954..18c9d46e0b85 100644
@@ -697,7 +697,8 @@ static void uart_throttle(struct tty_struct *tty)
 		mask |= UPSTAT_AUTORTS;
 
 	if (port->status & mask) {

This if condition is always false if driver did not set UPSTAT_AUTORTS nor UPSTAT_AUTOXOFF in port->status.

Quoted 10 lines

drivers/tty/serial/serial_core.c static void uart_throttle(struct tty_struct *tty) · line 704

Quoted 6 lines
drivers/tty/serial/serial_core.c +2 -1
-		port->ops->throttle(port);
+		if (port->ops->throttle)
+			port->ops->throttle(port);
 		mask &= ~port->status;
 	}
 

I think this patch is incorrect. The assumption is not ".throttle is always set" but rather ".throttle is set when UPSTAT_AUTORTS or UPSTAT_AUTOXOFF is set".

Right, I kind of ended up concluding that's likely the case after sending the patch when looking into 9aba8d5b0111 (SERIAL: core: add throttle/unthrottle callbacks for hardware assisted flow control).

Signature · 1 line
 i.