linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] isdn: hfcpci: fix potential NULL pointer dereference
@ 2019-03-12  5:54 Kangjie Lu
  2019-03-12 21:36 ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Kangjie Lu @ 2019-03-12  5:54 UTC (permalink / raw)
  To: kjlu
  Cc: pakki001, Karsten Keil, David S. Miller, Gustavo A. R. Silva,
	Jia-Ju Bai, netdev, linux-kernel

In case ioremap fails, the fix releases resources and returns.
The following printk is for logging purpose and thus is
preserved.

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

diff --git a/drivers/isdn/hardware/mISDN/hfcpci.c b/drivers/isdn/hardware/mISDN/hfcpci.c
index ebb3fa2e1d00..362aa5450a5e 100644
--- a/drivers/isdn/hardware/mISDN/hfcpci.c
+++ b/drivers/isdn/hardware/mISDN/hfcpci.c
@@ -2032,10 +2032,19 @@ setup_hw(struct hfc_pci *hc)
 	hc->hw.fifos = buffer;
 	pci_write_config_dword(hc->pdev, 0x80, hc->hw.dmahandle);
 	hc->hw.pci_io = ioremap((ulong) hc->hw.pci_io, 256);
+	if (unlikely(!hc->hw.pci_io)) {
+		printk(KERN_WARNING
+		       "HFC-PCI: Error in ioremap for PCI!\n");
+		pci_free_consistent(hc->pdev, 0x8000, hc->hw.fifos,
+				    hc->hw.dmahandle);
+		return 1;
+	}
+
 	printk(KERN_INFO
 	       "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);
+
 	/* enable memory mapped ports, disable busmaster */
 	pci_write_config_word(hc->pdev, PCI_COMMAND, PCI_ENA_MEMIO);
 	hc->hw.int_m2 = 0;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] isdn: hfcpci: fix potential NULL pointer dereference
  2019-03-12  5:54 [PATCH v2] isdn: hfcpci: fix potential NULL pointer dereference Kangjie Lu
@ 2019-03-12 21:36 ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2019-03-12 21:36 UTC (permalink / raw)
  To: kjlu; +Cc: pakki001, isdn, gustavo, baijiaju1990, netdev, linux-kernel

From: Kangjie Lu <kjlu@umn.edu>
Date: Tue, 12 Mar 2019 00:54:55 -0500

> In case ioremap fails, the fix releases resources and returns.
> The following printk is for logging purpose and thus is
> preserved.
> 
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>

Applied.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] isdn: hfcpci: fix potential NULL pointer dereference
  2019-03-11  5:34 Kangjie Lu
@ 2019-03-11 19:14 ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2019-03-11 19:14 UTC (permalink / raw)
  To: kjlu; +Cc: pakki001, isdn, gustavo, baijiaju1990, netdev, linux-kernel

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] isdn: hfcpci: fix potential NULL pointer dereference
@ 2019-03-11  5:34 Kangjie Lu
  2019-03-11 19:14 ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Kangjie Lu @ 2019-03-11  5:34 UTC (permalink / raw)
  To: kjlu
  Cc: pakki001, Karsten Keil, David S. Miller, Gustavo A. R. Silva,
	Jia-Ju Bai, netdev, linux-kernel

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;
+	}
+
 	/* enable memory mapped ports, disable busmaster */
 	pci_write_config_word(hc->pdev, PCI_COMMAND, PCI_ENA_MEMIO);
 	hc->hw.int_m2 = 0;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-03-12 21:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-12  5:54 [PATCH v2] isdn: hfcpci: fix potential NULL pointer dereference Kangjie Lu
2019-03-12 21:36 ` David Miller
  -- strict thread matches above, loose matches on Subject: below --
2019-03-11  5:34 Kangjie Lu
2019-03-11 19:14 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).