Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

8250_lpss: check null return when calling pci_ioremap_bar

pci_ioremap_bar may return null. This is eventually de-referenced at
drivers/dma/dw/core.c:1154 and drivers/dma/dw/core.c:1168. A null check
is needed to prevent null de-reference. I am adding the check and in
case of failure. Thanks to Andy Shevchenko for the hint on the necessity
of pci_iounmap when exiting.

Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20190719174848.24216-1-navid.emamdoost@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Navid Emamdoost and committed by
Greg Kroah-Hartman
ea5ab2e4 f77ebb24

+8 -2
+8 -2
drivers/tty/serial/8250/8250_lpss.c
··· 169 169 struct pci_dev *pdev = to_pci_dev(port->dev); 170 170 int ret; 171 171 172 + chip->pdata = &qrk_serial_dma_pdata; 172 173 chip->dev = &pdev->dev; 173 174 chip->irq = pci_irq_vector(pdev, 0); 174 175 chip->regs = pci_ioremap_bar(pdev, 1); 175 - chip->pdata = &qrk_serial_dma_pdata; 176 + if (!chip->regs) 177 + return; 176 178 177 179 /* Falling back to PIO mode if DMA probing fails */ 178 180 ret = dw_dma_probe(chip); ··· 197 195 198 196 static void qrk_serial_exit_dma(struct lpss8250 *lpss) 199 197 { 198 + struct dw_dma_chip *chip = &lpss->dma_chip; 200 199 struct dw_dma_slave *param = &lpss->dma_param; 201 200 202 201 if (!param->dma_dev) 203 202 return; 204 - dw_dma_remove(&lpss->dma_chip); 203 + 204 + dw_dma_remove(chip); 205 + 206 + pci_iounmap(to_pci_dev(chip->dev), chip->regs); 205 207 } 206 208 #else /* CONFIG_SERIAL_8250_DMA */ 207 209 static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port) {}