Linux Serial subsystem development
 help / color / mirror / Atom feed
* [RFC PATCH] serial: Don't assume uart_ops .throttle is always set
@ 2022-04-28 17:11 Ilpo Järvinen
  2022-04-28 18:37 ` Greg KH
  2022-04-29  5:21 ` Tomasz Mon
  0 siblings, 2 replies; 4+ messages in thread
From: Ilpo Järvinen @ 2022-04-28 17:11 UTC (permalink / raw)
  To: Nuno Gonçalves; +Cc: linux-serial

[-- Attachment #1: Type: text/plain, Size: 930 bytes --]

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.

Reported-by: Nuno Gonçalves <nunojpg@gmail.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

---
 drivers/tty/serial/serial_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 6a8963caf954..18c9d46e0b85 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -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;
 	}
 

-- 
tg: (19317433057d..) serial/fix-uart_throttle (depends on: tty-linus)

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [RFC PATCH] serial: Don't assume uart_ops .throttle is always set
  2022-04-28 17:11 [RFC PATCH] serial: Don't assume uart_ops .throttle is always set Ilpo Järvinen
@ 2022-04-28 18:37 ` Greg KH
  2022-04-29  5:21 ` Tomasz Mon
  1 sibling, 0 replies; 4+ messages in thread
From: Greg KH @ 2022-04-28 18:37 UTC (permalink / raw)
  To: Ilpo Järvinen; +Cc: Nuno Gonçalves, linux-serial

On Thu, Apr 28, 2022 at 08:11:56PM +0300, Ilpo Järvinen wrote:
> 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.
> 
> Reported-by: Nuno Gonçalves <nunojpg@gmail.com>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> 
> ---
>  drivers/tty/serial/serial_core.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> index 6a8963caf954..18c9d46e0b85 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC PATCH] serial: Don't assume uart_ops .throttle is always set
  2022-04-28 17:11 [RFC PATCH] serial: Don't assume uart_ops .throttle is always set Ilpo Järvinen
  2022-04-28 18:37 ` Greg KH
@ 2022-04-29  5:21 ` Tomasz Mon
  2022-04-29  7:19   ` Ilpo Järvinen
  1 sibling, 1 reply; 4+ messages in thread
From: Tomasz Mon @ 2022-04-29  5:21 UTC (permalink / raw)
  To: ilpo.jarvinen@linux.intel.com, nunojpg@gmail.com
  Cc: linux-serial@vger.kernel.org, Tomasz Mon

On Thu, 2022-04-28 at 20:11 +0300, Ilpo Järvinen wrote:
> 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.

> diff --git a/drivers/tty/serial/serial_core.c
> b/drivers/tty/serial/serial_core.c
> index 6a8963caf954..18c9d46e0b85 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -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.

> -		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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC PATCH] serial: Don't assume uart_ops .throttle is always set
  2022-04-29  5:21 ` Tomasz Mon
@ 2022-04-29  7:19   ` Ilpo Järvinen
  0 siblings, 0 replies; 4+ messages in thread
From: Ilpo Järvinen @ 2022-04-29  7:19 UTC (permalink / raw)
  To: Tomasz Mon; +Cc: nunojpg@gmail.com, linux-serial@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 1447 bytes --]

On Fri, 29 Apr 2022, Tomasz Mon wrote:

> On Thu, 2022-04-28 at 20:11 +0300, Ilpo Järvinen wrote:
> > 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.
> 
> > diff --git a/drivers/tty/serial/serial_core.c
> > b/drivers/tty/serial/serial_core.c
> > index 6a8963caf954..18c9d46e0b85 100644
> > --- a/drivers/tty/serial/serial_core.c
> > +++ b/drivers/tty/serial/serial_core.c
> > @@ -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.
> 
> > -		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).


-- 
 i.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-04-29  7:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-28 17:11 [RFC PATCH] serial: Don't assume uart_ops .throttle is always set Ilpo Järvinen
2022-04-28 18:37 ` Greg KH
2022-04-29  5:21 ` Tomasz Mon
2022-04-29  7:19   ` Ilpo Järvinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox