* [PATCH] tty: serial: fsl_lpuart: make coverity happy
@ 2020-04-03 17:49 Michael Walle
2020-04-06 4:27 ` Jiri Slaby
2020-04-06 14:51 ` Fabio Estevam
0 siblings, 2 replies; 3+ messages in thread
From: Michael Walle @ 2020-04-03 17:49 UTC (permalink / raw)
To: linux-kernel, linux-serial
Cc: Greg Kroah-Hartman, Jiri Slaby, Colin Ian King, NXP Linux Team,
Michael Walle
Coverity reports the following:
var_compare_op: Comparing chan to null implies that chan might be null.
1234 if (chan)
1235 dmaengine_terminate_all(chan);
1236
Dereference after null check (FORWARD_NULL)
var_deref_op: Dereferencing null pointer chan.
1237 dma_unmap_sg(chan->device->dev, &sport->rx_sgl, 1, DMA_FROM_DEVICE);
Technically, this is correct. But lpuart_dma_rx_free() is guarded by
lpuart_dma_rx_use which is only true if there is a dma channel, see
lpuart_rx_dma_startup(). In any way, this looks bogus. So remove
the superfluous "if (chan)" check and make coverity happy.
Fixes: a092ab25fdaa ("tty: serial: fsl_lpuart: fix DMA mapping")
Signed-off-by: Michael Walle <michael@walle.cc>
Reported-by: Colin Ian King <colin.king@canonical.com>
---
drivers/tty/serial/fsl_lpuart.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index 4cb04d8bf034..83d803729d23 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -1210,9 +1210,7 @@ static void lpuart_dma_rx_free(struct uart_port *port)
struct lpuart_port, port);
struct dma_chan *chan = sport->dma_rx_chan;
- if (chan)
- dmaengine_terminate_all(chan);
-
+ dmaengine_terminate_all(chan);
dma_unmap_sg(chan->device->dev, &sport->rx_sgl, 1, DMA_FROM_DEVICE);
kfree(sport->rx_ring.buf);
sport->rx_ring.tail = 0;
--
2.20.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] tty: serial: fsl_lpuart: make coverity happy
2020-04-03 17:49 [PATCH] tty: serial: fsl_lpuart: make coverity happy Michael Walle
@ 2020-04-06 4:27 ` Jiri Slaby
2020-04-06 14:51 ` Fabio Estevam
1 sibling, 0 replies; 3+ messages in thread
From: Jiri Slaby @ 2020-04-06 4:27 UTC (permalink / raw)
To: Michael Walle, linux-kernel, linux-serial
Cc: Greg Kroah-Hartman, Colin Ian King, NXP Linux Team
On 03. 04. 20, 19:49, Michael Walle wrote:
> Coverity reports the following:
>
> var_compare_op: Comparing chan to null implies that chan might be null.
>
> 1234 if (chan)
> 1235 dmaengine_terminate_all(chan);
> 1236
>
> Dereference after null check (FORWARD_NULL)
> var_deref_op: Dereferencing null pointer chan.
>
> 1237 dma_unmap_sg(chan->device->dev, &sport->rx_sgl, 1, DMA_FROM_DEVICE);
>
> Technically, this is correct. But lpuart_dma_rx_free() is guarded by
> lpuart_dma_rx_use which is only true if there is a dma channel, see
> lpuart_rx_dma_startup(). In any way, this looks bogus. So remove
> the superfluous "if (chan)" check and make coverity happy.
>
> Fixes: a092ab25fdaa ("tty: serial: fsl_lpuart: fix DMA mapping")
> Signed-off-by: Michael Walle <michael@walle.cc>
> Reported-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Jiri Slaby <jslaby@suse.cz>
> ---
> drivers/tty/serial/fsl_lpuart.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
> index 4cb04d8bf034..83d803729d23 100644
> --- a/drivers/tty/serial/fsl_lpuart.c
> +++ b/drivers/tty/serial/fsl_lpuart.c
> @@ -1210,9 +1210,7 @@ static void lpuart_dma_rx_free(struct uart_port *port)
> struct lpuart_port, port);
> struct dma_chan *chan = sport->dma_rx_chan;
>
> - if (chan)
> - dmaengine_terminate_all(chan);
> -
> + dmaengine_terminate_all(chan);
> dma_unmap_sg(chan->device->dev, &sport->rx_sgl, 1, DMA_FROM_DEVICE);
> kfree(sport->rx_ring.buf);
> sport->rx_ring.tail = 0;
>
thanks,
--
js
suse labs
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tty: serial: fsl_lpuart: make coverity happy
2020-04-03 17:49 [PATCH] tty: serial: fsl_lpuart: make coverity happy Michael Walle
2020-04-06 4:27 ` Jiri Slaby
@ 2020-04-06 14:51 ` Fabio Estevam
1 sibling, 0 replies; 3+ messages in thread
From: Fabio Estevam @ 2020-04-06 14:51 UTC (permalink / raw)
To: Michael Walle
Cc: linux-kernel, linux-serial, Greg Kroah-Hartman, Jiri Slaby,
Colin Ian King, NXP Linux Team
On Fri, Apr 3, 2020 at 2:50 PM Michael Walle <michael@walle.cc> wrote:
>
> Coverity reports the following:
>
> var_compare_op: Comparing chan to null implies that chan might be null.
>
> 1234 if (chan)
> 1235 dmaengine_terminate_all(chan);
> 1236
>
> Dereference after null check (FORWARD_NULL)
> var_deref_op: Dereferencing null pointer chan.
>
> 1237 dma_unmap_sg(chan->device->dev, &sport->rx_sgl, 1, DMA_FROM_DEVICE);
>
> Technically, this is correct. But lpuart_dma_rx_free() is guarded by
> lpuart_dma_rx_use which is only true if there is a dma channel, see
> lpuart_rx_dma_startup(). In any way, this looks bogus. So remove
> the superfluous "if (chan)" check and make coverity happy.
>
> Fixes: a092ab25fdaa ("tty: serial: fsl_lpuart: fix DMA mapping")
> Signed-off-by: Michael Walle <michael@walle.cc>
> Reported-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Fabio Estevam <festevam@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-04-06 14:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-03 17:49 [PATCH] tty: serial: fsl_lpuart: make coverity happy Michael Walle
2020-04-06 4:27 ` Jiri Slaby
2020-04-06 14:51 ` Fabio Estevam
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).