tty: atmel_serial: fix a potential NULL pointer dereference [Linux 3.16.72]

This Linux kernel change "tty: atmel_serial: fix a potential NULL pointer dereference" is included in the Linux 3.16.72 release. This change is authored by Kangjie Lu <kjlu [at] umn.edu> on Fri Mar 15 12:16:06 2019 -0500. The commit for this change in Linux stable tree is cf592ae (patch) which is from upstream commit c85be04. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream c85be04.

tty: atmel_serial: fix a potential NULL pointer dereference

commit c85be041065c0be8bc48eda4c45e0319caf1d0e5 upstream.

In case dmaengine_prep_dma_cyclic fails, the fix returns a proper
error code to avoid NULL pointer dereference.

Signed-off-by: Kangjie Lu <[email protected]>
Fixes: 34df42f59a60 ("serial: at91: add rx dma support")
Acked-by: Richard Genoud <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
[bwh: Backported to 3.16: adjust context]
Signed-off-by: Ben Hutchings <[email protected]>

There are 4 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/tty/serial/atmel_serial.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index bc1c68c..d867671 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -1045,6 +1045,10 @@ static int atmel_prepare_rx_dma(struct uart_port *port)
                sg_dma_len(&atmel_port->sg_rx)/2,
                DMA_DEV_TO_MEM,
                DMA_PREP_INTERRUPT);
+   if (!desc) {
+       dev_err(port->dev, "Preparing DMA cyclic failed\n");
+       goto chan_err;
+   }
    desc->callback = atmel_complete_rx_dma;
    desc->callback_param = port;
    atmel_port->desc_rx = desc;

Leave a Reply

Your email address will not be published. Required fields are marked *