Skip to content

Commit f70f95b

Browse files
Jiri Slaby (SUSE)gregkh
authored andcommitted
serial: msm: check dma_map_sg() return value properly
The -next commit f8fef2f (tty: msm_serial: use dmaengine_prep_slave_sg()), switched to using dma_map_sg(). But the return value of dma_map_sg() is special: it returns number of elements mapped. And not a standard error value. The commit also forgot to reset dma->tx_sg in case of this failure. Fix both these mistakes. Thanks to Marek who helped debugging this. Signed-off-by: Jiri Slaby (SUSE) <[email protected]> Reported-by: Marek Szyprowski <[email protected]> Tested-by: Marek Szyprowski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c6795fb commit f70f95b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

drivers/tty/serial/msm_serial.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,15 +499,18 @@ static int msm_handle_tx_dma(struct msm_port *msm_port, unsigned int count)
499499
struct uart_port *port = &msm_port->uart;
500500
struct tty_port *tport = &port->state->port;
501501
struct msm_dma *dma = &msm_port->tx_dma;
502+
unsigned int mapped;
502503
int ret;
503504
u32 val;
504505

505506
sg_init_table(&dma->tx_sg, 1);
506507
kfifo_dma_out_prepare(&tport->xmit_fifo, &dma->tx_sg, 1, count);
507508

508-
ret = dma_map_sg(port->dev, &dma->tx_sg, 1, dma->dir);
509-
if (ret)
510-
return ret;
509+
mapped = dma_map_sg(port->dev, &dma->tx_sg, 1, dma->dir);
510+
if (!mapped) {
511+
ret = -EIO;
512+
goto zero_sg;
513+
}
511514

512515
dma->desc = dmaengine_prep_slave_sg(dma->chan, &dma->tx_sg, 1,
513516
DMA_MEM_TO_DEV,
@@ -548,6 +551,7 @@ static int msm_handle_tx_dma(struct msm_port *msm_port, unsigned int count)
548551
return 0;
549552
unmap:
550553
dma_unmap_sg(port->dev, &dma->tx_sg, 1, dma->dir);
554+
zero_sg:
551555
sg_init_table(&dma->tx_sg, 1);
552556
return ret;
553557
}

0 commit comments

Comments
 (0)