Subject: [PATCH] pci_alloc_consistent() crash

From: Geert Uytterhoeven <[email-masked]>
Date: Fri, 23 May 2003 15:51:00 +0200 (MEST)

Hi Ralf,

Avoid a NULL-pointer dereference when using pci_alloc_consistent() for PCI-like
buses (i.e. hwdev = NULL).

--- linux-mips-2.4.x/arch/mips/kernel/pci-dma.c	Tue Apr  1 16:21:18 2003
+++ linux/arch/mips/kernel/pci-dma.c	Thu May 15 18:17:35 2003
@@ -21,6 +21,7 @@
 {
 	void *ret;
 	int gfp = GFP_ATOMIC;
+	struct pci_bus *bus = NULL;
 
 #ifdef CONFIG_ISA
 	if (hwdev == NULL || hwdev->dma_mask != 0xffffffff)
@@ -30,7 +31,9 @@
 
 	if (ret != NULL) {
 		memset(ret, 0, size);
-		*dma_handle = bus_to_baddr(hwdev->bus, __pa(ret));
+		if (hwdev)
+			bus = hwdev->bus;
+		*dma_handle = bus_to_baddr(bus, __pa(ret));
 #ifdef CONFIG_NONCOHERENT_IO
 		dma_cache_wback_inv((unsigned long) ret, size);
 		ret = UNCAC_ADDR(ret);

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email-masked]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

---

From: Ralf Baechle <[email-masked]>
Date: Tue, 27 May 2003 06:18:30 +0200

On Fri, May 23, 2003 at 03:51:00PM +0200, Geert Uytterhoeven wrote:

> Avoid a NULL-pointer dereference when using pci_alloc_consistent() for
> PCI-like buses (i.e. hwdev = NULL).

Thanks, applied.

  Ralf