diff mbox series

[v2] isdn: hfcpci: fix potential NULL pointer dereference

Message ID 20190311053436.10747-1-kjlu@umn.edu
State Changes Requested
Delegated to: David Miller
Headers show
Series [v2] isdn: hfcpci: fix potential NULL pointer dereference | expand

Commit Message

Kangjie Lu March 11, 2019, 5:34 a.m. UTC
In case ioremap fails, the fix releases resources and returns.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
 drivers/isdn/hardware/mISDN/hfcpci.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

David Miller March 11, 2019, 7:14 p.m. UTC | #1
From: Kangjie Lu <kjlu@umn.edu>
Date: Mon, 11 Mar 2019 00:34:34 -0500

> In case ioremap fails, the fix releases resources and returns.
> 
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
> ---
>  drivers/isdn/hardware/mISDN/hfcpci.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/isdn/hardware/mISDN/hfcpci.c b/drivers/isdn/hardware/mISDN/hfcpci.c
> index ebb3fa2e1d00..d1d53c5de3c0 100644
> --- a/drivers/isdn/hardware/mISDN/hfcpci.c
> +++ b/drivers/isdn/hardware/mISDN/hfcpci.c
> @@ -2036,6 +2036,12 @@ setup_hw(struct hfc_pci *hc)
>  	       "HFC-PCI: defined at mem %#lx fifo %#lx(%#lx) IRQ %d HZ %d\n",
>  	       (u_long) hc->hw.pci_io, (u_long) hc->hw.fifos,
>  	       (u_long) hc->hw.dmahandle, hc->irq, HZ);
> +	if (unlikely(!hc->hw.pci_io)) {
> +		pci_free_consistent(hc->pdev, 0x8000, hc->hw.fifos,
> +				    hc->hw.dmahandle);
> +		return 1;
> +	}

The log message emitted before this new check reports detection of the
device, which you should not do if we are going to fail the probe.
diff mbox series

Patch

diff --git a/drivers/isdn/hardware/mISDN/hfcpci.c b/drivers/isdn/hardware/mISDN/hfcpci.c
index ebb3fa2e1d00..d1d53c5de3c0 100644
--- a/drivers/isdn/hardware/mISDN/hfcpci.c
+++ b/drivers/isdn/hardware/mISDN/hfcpci.c
@@ -2036,6 +2036,12 @@  setup_hw(struct hfc_pci *hc)
 	       "HFC-PCI: defined at mem %#lx fifo %#lx(%#lx) IRQ %d HZ %d\n",
 	       (u_long) hc->hw.pci_io, (u_long) hc->hw.fifos,
 	       (u_long) hc->hw.dmahandle, hc->irq, HZ);
+	if (unlikely(!hc->hw.pci_io)) {
+		pci_free_consistent(hc->pdev, 0x8000, hc->hw.fifos,
+				    hc->hw.dmahandle);
+		return 1;
+	}
+
 	/* enable memory mapped ports, disable busmaster */
 	pci_write_config_word(hc->pdev, PCI_COMMAND, PCI_ENA_MEMIO);
 	hc->hw.int_m2 = 0;