Skip to contentSkip to conversation

tty: serial: fsl_lpuart: fix DMA mapping

bug report Dan Carpenter 2 participants 2 messages Apr 6, 2020 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

Hello Michael Walle,

This is a semi-automatic email about new static checker warnings.

The patch a092ab25fdaa: "tty: serial: fsl_lpuart: fix DMA mapping" from Mar 6, 2020, leads to the following Smatch complaint:

drivers/tty/serial/fsl_lpuart.c:1237 lpuart_dma_rx_free()
error: we previously assumed 'chan' could be null (see line 1234)

drivers/tty/serial/fsl_lpuart.c
1228 static void lpuart_dma_rx_free(struct uart_port *port) 1229 {
1230 struct lpuart_port *sport = container_of(port,
1231 struct lpuart_port, port);
1232 struct dma_chan *chan = sport->dma_rx_chan;
1233
1234 if (chan)

                    ^^^^

The patch adds a check

1235 dmaengine_terminate_all(chan);
1236

  1237		dma_unmap_sg(chan->device->dev, &sport->rx_sgl, 1, DMA_FROM_DEVICE);
                             ^^^^^^

and an unchecked dereference.

  1238		kfree(sport->rx_ring.buf);
  1239		sport->rx_ring.tail = 0;

regards,
dan carpenter

#1 lore raw

Am 2020-04-06 16:42, schrieb Dan Carpenter:

Quoted 3 lines

Hello Michael Walle,

This is a semi-automatic email about new static checker warnings.

Thanks, fix is pending, see here:

https://lore.kernel.org/linux-serial/[email protected]/

-michael

Quoted 31 lines

The patch a092ab25fdaa: "tty: serial: fsl_lpuart: fix DMA mapping" from Mar 6, 2020, leads to the following Smatch complaint:

drivers/tty/serial/fsl_lpuart.c:1237 lpuart_dma_rx_free()
error: we previously assumed 'chan' could be null (see line 1234)

drivers/tty/serial/fsl_lpuart.c
1228 static void lpuart_dma_rx_free(struct uart_port *port) 1229 {
1230 struct lpuart_port *sport = container_of(port,
1231 struct lpuart_port,
port);
1232 struct dma_chan *chan = sport->dma_rx_chan;
1233
1234 if (chan)

                    ^^^^

The patch adds a check

1235 dmaengine_terminate_all(chan);
1236
1237 dma_unmap_sg(chan->device->dev, &sport->rx_sgl, 1,

DMA_FROM_DEVICE);
                             ^^^^^^

and an unchecked dereference.

  1238		kfree(sport->rx_ring.buf);
  1239		sport->rx_ring.tail = 0;

regards,
dan carpenter