* [PATCH v2] tty: serial: fsl_lpuart.c: prevent a bad shift operation
@ 2020-07-21 17:42 B K Karthik
2020-07-29 16:03 ` Greg Kroah-Hartman
0 siblings, 1 reply; 5+ messages in thread
From: B K Karthik @ 2020-07-21 17:42 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby, linux-serial, linux-kernel,
Vabhav Sharma (OSS),
bhuvanchandra.dv
[-- Attachment #1: Type: text/plain, Size: 1020 bytes --]
prevent a bad shift operation by verifying that
the argument to fls is non zero.
Reported-by: "Vabhav Sharma (OSS)" <vabhav.sharma@oss.nxp.com>
Signed-off-by: B K Karthik <bkkarthik@pesu.pes.edu>
---
v1 -> v2:
added Reported-by tag
drivers/tty/serial/fsl_lpuart.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index 7ca642249224..0cc64279cd2d 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -1168,7 +1168,8 @@ static inline int lpuart_start_rx_dma(struct lpuart_port *sport)
* 10ms at any baud rate.
*/
sport->rx_dma_rng_buf_len = (DMA_RX_TIMEOUT * baud / bits / 1000) * 2;
- sport->rx_dma_rng_buf_len = (1 << (fls(sport->rx_dma_rng_buf_len) - 1));
+ if (sport->rx_dma_rng_buf_len != 0)
+ sport->rx_dma_rng_buf_len = (1 << (fls(sport->rx_dma_rng_buf_len) - 1));
if (sport->rx_dma_rng_buf_len < 16)
sport->rx_dma_rng_buf_len = 16;
--
2.20.1
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] tty: serial: fsl_lpuart.c: prevent a bad shift operation
2020-07-21 17:42 [PATCH v2] tty: serial: fsl_lpuart.c: prevent a bad shift operation B K Karthik
@ 2020-07-29 16:03 ` Greg Kroah-Hartman
2020-08-05 12:09 ` Vabhav Sharma (OSS)
0 siblings, 1 reply; 5+ messages in thread
From: Greg Kroah-Hartman @ 2020-07-29 16:03 UTC (permalink / raw)
To: B K Karthik
Cc: Jiri Slaby, linux-serial, linux-kernel, Vabhav Sharma (OSS),
bhuvanchandra.dv
On Tue, Jul 21, 2020 at 11:12:29PM +0530, B K Karthik wrote:
> prevent a bad shift operation by verifying that
> the argument to fls is non zero.
>
> Reported-by: "Vabhav Sharma (OSS)" <vabhav.sharma@oss.nxp.com>
> Signed-off-by: B K Karthik <bkkarthik@pesu.pes.edu>
> ---
> v1 -> v2:
> added Reported-by tag
>
> drivers/tty/serial/fsl_lpuart.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
> index 7ca642249224..0cc64279cd2d 100644
> --- a/drivers/tty/serial/fsl_lpuart.c
> +++ b/drivers/tty/serial/fsl_lpuart.c
> @@ -1168,7 +1168,8 @@ static inline int lpuart_start_rx_dma(struct lpuart_port *sport)
> * 10ms at any baud rate.
> */
> sport->rx_dma_rng_buf_len = (DMA_RX_TIMEOUT * baud / bits / 1000) * 2;
> - sport->rx_dma_rng_buf_len = (1 << (fls(sport->rx_dma_rng_buf_len) - 1));
> + if (sport->rx_dma_rng_buf_len != 0)
How can this variable become 0?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH v2] tty: serial: fsl_lpuart.c: prevent a bad shift operation
2020-07-29 16:03 ` Greg Kroah-Hartman
@ 2020-08-05 12:09 ` Vabhav Sharma (OSS)
2020-08-05 12:56 ` Greg Kroah-Hartman
0 siblings, 1 reply; 5+ messages in thread
From: Vabhav Sharma (OSS) @ 2020-08-05 12:09 UTC (permalink / raw)
To: Greg Kroah-Hartman, B K Karthik
Cc: Jiri Slaby, linux-serial, linux-kernel, Vabhav Sharma (OSS),
bhuvanchandra.dv
> -----Original Message-----
> From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Sent: Wednesday, July 29, 2020 9:34 PM
> To: B K Karthik <bkkarthik@pesu.pes.edu>
> Cc: Jiri Slaby <jirislaby@kernel.org>; linux-serial@vger.kernel.org; linux-
> kernel@vger.kernel.org; Vabhav Sharma (OSS)
> <vabhav.sharma@oss.nxp.com>; bhuvanchandra.dv@toradex.com
> Subject: Re: [PATCH v2] tty: serial: fsl_lpuart.c: prevent a bad shift operation
>
> On Tue, Jul 21, 2020 at 11:12:29PM +0530, B K Karthik wrote:
> > prevent a bad shift operation by verifying that the argument to fls is
> > non zero.
> >
> > Reported-by: "Vabhav Sharma (OSS)" <vabhav.sharma@oss.nxp.com>
> > Signed-off-by: B K Karthik <bkkarthik@pesu.pes.edu>
> > ---
> > v1 -> v2:
> > added Reported-by tag
> >
> > drivers/tty/serial/fsl_lpuart.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/tty/serial/fsl_lpuart.c
> > b/drivers/tty/serial/fsl_lpuart.c index 7ca642249224..0cc64279cd2d
> > 100644
> > --- a/drivers/tty/serial/fsl_lpuart.c
> > +++ b/drivers/tty/serial/fsl_lpuart.c
> > @@ -1168,7 +1168,8 @@ static inline int lpuart_start_rx_dma(struct
> lpuart_port *sport)
> > * 10ms at any baud rate.
> > */
> > sport->rx_dma_rng_buf_len = (DMA_RX_TIMEOUT * baud / bits /
> 1000) * 2;
> > - sport->rx_dma_rng_buf_len = (1 << (fls(sport->rx_dma_rng_buf_len)
> - 1));
> > + if (sport->rx_dma_rng_buf_len != 0)
>
> How can this variable become 0?
Condition x, taking false branch
Explicitly returning zero
static __always_inline int fls(unsigned int x)
{
return x ? sizeof(x) * 8 - __builtin_clz(x) : 0;
}
>
> thanks,
>
> greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] tty: serial: fsl_lpuart.c: prevent a bad shift operation
2020-08-05 12:09 ` Vabhav Sharma (OSS)
@ 2020-08-05 12:56 ` Greg Kroah-Hartman
2020-08-05 13:16 ` B K Karthik
0 siblings, 1 reply; 5+ messages in thread
From: Greg Kroah-Hartman @ 2020-08-05 12:56 UTC (permalink / raw)
To: Vabhav Sharma (OSS)
Cc: B K Karthik, Jiri Slaby, linux-serial, linux-kernel, bhuvanchandra.dv
On Wed, Aug 05, 2020 at 12:09:34PM +0000, Vabhav Sharma (OSS) wrote:
>
>
> > -----Original Message-----
> > From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Sent: Wednesday, July 29, 2020 9:34 PM
> > To: B K Karthik <bkkarthik@pesu.pes.edu>
> > Cc: Jiri Slaby <jirislaby@kernel.org>; linux-serial@vger.kernel.org; linux-
> > kernel@vger.kernel.org; Vabhav Sharma (OSS)
> > <vabhav.sharma@oss.nxp.com>; bhuvanchandra.dv@toradex.com
> > Subject: Re: [PATCH v2] tty: serial: fsl_lpuart.c: prevent a bad shift operation
> >
> > On Tue, Jul 21, 2020 at 11:12:29PM +0530, B K Karthik wrote:
> > > prevent a bad shift operation by verifying that the argument to fls is
> > > non zero.
> > >
> > > Reported-by: "Vabhav Sharma (OSS)" <vabhav.sharma@oss.nxp.com>
> > > Signed-off-by: B K Karthik <bkkarthik@pesu.pes.edu>
> > > ---
> > > v1 -> v2:
> > > added Reported-by tag
> > >
> > > drivers/tty/serial/fsl_lpuart.c | 3 ++-
> > > 1 file changed, 2 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/tty/serial/fsl_lpuart.c
> > > b/drivers/tty/serial/fsl_lpuart.c index 7ca642249224..0cc64279cd2d
> > > 100644
> > > --- a/drivers/tty/serial/fsl_lpuart.c
> > > +++ b/drivers/tty/serial/fsl_lpuart.c
> > > @@ -1168,7 +1168,8 @@ static inline int lpuart_start_rx_dma(struct
> > lpuart_port *sport)
> > > * 10ms at any baud rate.
> > > */
> > > sport->rx_dma_rng_buf_len = (DMA_RX_TIMEOUT * baud / bits /
> > 1000) * 2;
> > > - sport->rx_dma_rng_buf_len = (1 << (fls(sport->rx_dma_rng_buf_len)
> > - 1));
> > > + if (sport->rx_dma_rng_buf_len != 0)
> >
> > How can this variable become 0?
> Condition x, taking false branch
> Explicitly returning zero
>
> static __always_inline int fls(unsigned int x)
> {
> return x ? sizeof(x) * 8 - __builtin_clz(x) : 0;
> }
What false branch?
I don't see how this can ever be an issue in "the real world", can you
explain how it could ever be a problem?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] tty: serial: fsl_lpuart.c: prevent a bad shift operation
2020-08-05 12:56 ` Greg Kroah-Hartman
@ 2020-08-05 13:16 ` B K Karthik
0 siblings, 0 replies; 5+ messages in thread
From: B K Karthik @ 2020-08-05 13:16 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Vabhav Sharma (OSS),
Jiri Slaby, linux-serial, linux-kernel, bhuvanchandra.dv
On Wed, Aug 5, 2020 at 6:26 PM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> On Wed, Aug 05, 2020 at 12:09:34PM +0000, Vabhav Sharma (OSS) wrote:
> >
> >
> > > -----Original Message-----
> > > From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > > Sent: Wednesday, July 29, 2020 9:34 PM
> > > To: B K Karthik <bkkarthik@pesu.pes.edu>
> > > Cc: Jiri Slaby <jirislaby@kernel.org>; linux-serial@vger.kernel.org; linux-
> > > kernel@vger.kernel.org; Vabhav Sharma (OSS)
> > > <vabhav.sharma@oss.nxp.com>; bhuvanchandra.dv@toradex.com
> > > Subject: Re: [PATCH v2] tty: serial: fsl_lpuart.c: prevent a bad shift operation
> > >
> > > On Tue, Jul 21, 2020 at 11:12:29PM +0530, B K Karthik wrote:
> > > > prevent a bad shift operation by verifying that the argument to fls is
> > > > non zero.
> > > >
> > > > Reported-by: "Vabhav Sharma (OSS)" <vabhav.sharma@oss.nxp.com>
> > > > Signed-off-by: B K Karthik <bkkarthik@pesu.pes.edu>
> > > > ---
> > > > v1 -> v2:
> > > > added Reported-by tag
> > > >
> > > > drivers/tty/serial/fsl_lpuart.c | 3 ++-
> > > > 1 file changed, 2 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/drivers/tty/serial/fsl_lpuart.c
> > > > b/drivers/tty/serial/fsl_lpuart.c index 7ca642249224..0cc64279cd2d
> > > > 100644
> > > > --- a/drivers/tty/serial/fsl_lpuart.c
> > > > +++ b/drivers/tty/serial/fsl_lpuart.c
> > > > @@ -1168,7 +1168,8 @@ static inline int lpuart_start_rx_dma(struct
> > > lpuart_port *sport)
> > > > * 10ms at any baud rate.
> > > > */
> > > > sport->rx_dma_rng_buf_len = (DMA_RX_TIMEOUT * baud / bits /
> > > 1000) * 2;
> > > > - sport->rx_dma_rng_buf_len = (1 << (fls(sport->rx_dma_rng_buf_len)
> > > - 1));
> > > > + if (sport->rx_dma_rng_buf_len != 0)
> > >
> > > How can this variable become 0?
> > Condition x, taking false branch
> > Explicitly returning zero
> >
> > static __always_inline int fls(unsigned int x)
> > {
> > return x ? sizeof(x) * 8 - __builtin_clz(x) : 0;
> > }
>
> What false branch?
I'm assuming he's talking about the value after : in the ? operator.
I am checking for the wrong thing in the if statement. We will have to
check for the return value of fls() before performing the shift.
I can change it and send a v3 if you agree.
Please let me know.
thanks,
karthik
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-08-05 20:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-21 17:42 [PATCH v2] tty: serial: fsl_lpuart.c: prevent a bad shift operation B K Karthik
2020-07-29 16:03 ` Greg Kroah-Hartman
2020-08-05 12:09 ` Vabhav Sharma (OSS)
2020-08-05 12:56 ` Greg Kroah-Hartman
2020-08-05 13:16 ` B K Karthik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).