tty: 8250: fix a missing check for pci_ioremap_bar
PATCH 1/1 tty: 8250: fix a missing check for pci_ioremap_bar
pci_ioremap_bar could fail. The fix captures the failure and pass an error code upstream. This can avoid potential NULL pointer dereferences in the future.
Signed-off-by Kangjie Lu <[email protected]>
--- drivers/tty/serial/8250/8250_lpss.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/tty/serial/8250/8250_lpss.c +8 -5
@@ -162,7 +162,7 @@ static const struct dw_dma_platform_data qrk_serial_dma_pdata = { .multi_block = {0}, }; -static void qrk_serial_setup_dma (struct lpss8250 *lpss,struct uart_port *port) +static int qrk_serial_setup_dma (struct lpss8250 *lpss,struct uart_port *port) {struct uart_8250_dma *dma = &lpss->dma;struct dw_dma_chip *chip = &lpss->dma_chip;
@@ -173,12 +173,14 @@ static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port) chip->dev = &pdev->dev; chip->irq =pci_irq_vector (pdev,0 ); chip->regs =pci_ioremap_bar (pdev,1 ); +if (!chip->regs) +return -EIO ; chip->pdata = &qrk_serial_dma_pdata;/* Falling back to PIO mode if DMA probing fails */ ret =dw_dma_probe (chip);if (ret) -return ; +return ret;pci_try_set_mwi (pdev);
@@ -192,6 +194,8 @@ static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port) param->hs_polarity = true; lpss->dma_maxburst =8 ; + +return 0 ; }static void qrk_serial_exit_dma (struct lpss8250 *lpss)
@@ -203,7 +207,7 @@ static void qrk_serial_exit_dma(struct lpss8250 *lpss) dw_dma_remove(&lpss->dma_chip); }#else /* CONFIG_SERIAL_8250_DMA */ -static void qrk_serial_setup_dma (struct lpss8250 *lpss,struct uart_port *port) {} +static int qrk_serial_setup_dma (struct lpss8250 *lpss,struct uart_port *port) {}static void qrk_serial_exit_dma (struct lpss8250 *lpss) {}#endif /* !CONFIG_SERIAL_8250_DMA */
@@ -220,8 +224,7 @@ static int qrk_serial_setup(struct lpss8250 *lpss, struct uart_port *port) port->irq =pci_irq_vector (pdev,0 ); -qrk_serial_setup_dma (lpss, port); -return 0 ; +return qrk_serial_setup_dma (lpss, port); }static void qrk_serial_exit (struct lpss8250 *lpss)
Signature · 1 line
2.17.1
Quoted 13 lines · Kangjie Lu
pci_ioremap_barcould fail. The fix captures the failure and pass an error code upstream. This can avoid potential NULL pointer dereferences in the future.Signed-off-by Kangjie Lu <[email protected]>--- drivers/tty/serial/8250/8250_lpss.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)drivers/tty/serial/8250/8250_lpss.c +0
-0
...
drivers/tty/serial/8250/8250_lpss.c static void qrk_serial_exit_dma(struct lpss8250 *lpss) · line 210
Quoted 6 lines
drivers/tty/serial/8250/8250_lpss.c +1
-1@@ -203,7 +207,7 @@ static void qrk_serial_exit_dma(struct lpss8250 *lpss) dw_dma_remove(&lpss->dma_chip); }#else /* CONFIG_SERIAL_8250_DMA */ -static void qrk_serial_setup_dma (struct lpss8250 *lpss,struct uart_port *port) {} +static int qrk_serial_setup_dma (struct lpss8250 *lpss,struct uart_port *port) {}
So you have to return something here now.
drivers/tty/serial/8250/8250_lpss.c static void qrk_serial_exit_dma(struct lpss8250 *lpss) · line 213
Quoted 3 lines
drivers/tty/serial/8250/8250_lpss.c +0
-0static void qrk_serial_exit_dma (struct lpss8250 *lpss) {}#endif /* !CONFIG_SERIAL_8250_DMA */
regards,
Signature · 2 lines
js suse labs