Skip to contentSkip to conversation

Fix ide-disk.c oops caused by hwif == NULL

PATCH NAK Geert Uytterhoeven 4 participants 6 messages Aug 10, 2005 – Aug 11, 2005 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 6 lines · Linux Kernel Mailing List

tree 518f62158f0923573decb8f072ac7282fb7575cb
parent aeb3f76350e78aba90653b563de6677b442d21d6
author Christoph Lameter <[email protected]> Wed, 10 Aug 2005 09:59:21 -0700 committer Linus Torvalds <[email protected]> Wed, 10 Aug 2005 10:21:31 -0700

[PATCH] Fix ide-disk.c oops caused by hwif == NULL

How can this patch fix that? It still dereferences hwif without checking for a NULL pointer.

Quoted 47 lines

1. Move hwif_to_node to ide.h

2. Use hwif_to_node in ide-disk.c

 drivers/ide/ide-disk.c  |    2 +-
 drivers/ide/ide-probe.c |    9 ---------
 include/linux/ide.h     |    6 ++++++
 3 files changed, 7 insertions(+), 10 deletions(-)
drivers/ide/ide-disk.c +1 -1
@@ -1220,7 +1220,7 @@ static int ide_disk_probe(struct device 
 		goto failed;
 
 	g = alloc_disk_node(1 << PARTN_BITS,
-			pcibus_to_node(drive->hwif->pci_dev->bus));
+			hwif_to_node(drive->hwif));
 	if (!g)
 		goto out_free_idkp;
 
drivers/ide/ide-probe.c +0 -9
@@ -960,15 +960,6 @@ static void save_match(ide_hwif_t *hwif,
 }
 #endif /* MAX_HWIFS > 1 */
 
-static inline int hwif_to_node(ide_hwif_t *hwif)
-{
-	if (hwif->pci_dev)
-		return pcibus_to_node(hwif->pci_dev->bus);
-	else
-		/* Add ways to determine the node of other busses here */
-		return -1;
-}
-
 /*
  * init request queue
  */

include/linux/ide.h extern struct bus_type ide_bus_type; · line 1506

Quoted 6 lines
include/linux/ide.h +3 -0
@@ -1501,4 +1501,10 @@ extern struct bus_type ide_bus_type;
 #define ide_id_has_flush_cache_ext(id)	\
 	(((id)->cfs_enable_2 & 0x2400) == 0x2400)
 
+static inline int hwif_to_node(ide_hwif_t *hwif)
+{
+	struct pci_dev *dev = hwif->pci_dev;
                              ^^^^^^^^^^^^^

include/linux/ide.h extern struct bus_type ide_bus_type; · line 1510

Quoted 4 lines
include/linux/ide.h +3 -0
+	return dev ? pcibus_to_node(dev->bus) : -1;
+}
+
 #endif /* _IDE_H */

Gr{oetje,eeting}s,

Geert

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

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

#2 lore raw
Quoted 10 lines · Geert Uytterhoeven
Quoted 6 lines · Linux Kernel Mailing List

tree 518f62158f0923573decb8f072ac7282fb7575cb
parent aeb3f76350e78aba90653b563de6677b442d21d6
author Christoph Lameter <[email protected]> Wed, 10 Aug 2005 09:59:21 -0700 committer Linus Torvalds <[email protected]> Wed, 10 Aug 2005 10:21:31 -0700

[PATCH] Fix ide-disk.c oops caused by hwif == NULL

How can this patch fix that? It still dereferences hwif without checking for a NULL pointer.

Correct. So we need to indeed go back to a version that does check for NULL that I initially proposed.

include/linux/ide.h +1 -1
Index: linux-2.6/include/linux/ide.h
===================================================================
@@ -1503,7 +1503,7 @@
 
 static inline int hwif_to_node(ide_hwif_t *hwif)
 {
-	if (hwif->pci_dev)
+	if (hwif && hwif->pci_dev)
 		return pcibus_to_node(hwif->pci_dev->bus);
 	else
 		/* Add ways to determine the node of other busses here */
#3 lore raw

NAK

hwif can't be NULL or something is *really* wrong

Quoted 29 lines · Christoph Lameter
Quoted 10 lines · Geert Uytterhoeven
Quoted 6 lines · Linux Kernel Mailing List

tree 518f62158f0923573decb8f072ac7282fb7575cb
parent aeb3f76350e78aba90653b563de6677b442d21d6
author Christoph Lameter <[email protected]> Wed, 10 Aug 2005 09:59:21 -0700 committer Linus Torvalds <[email protected]> Wed, 10 Aug 2005 10:21:31 -0700

[PATCH] Fix ide-disk.c oops caused by hwif == NULL

How can this patch fix that? It still dereferences hwif without checking for a NULL pointer.

Correct. So we need to indeed go back to a version that does check for NULL that I initially proposed.

Index: linux-2.6/include/linux/ide.h
===================================================================

include/linux/ide.h 2005-08-10 06:05:44.000000000 -0700 renamed from include/linux/ide.h 2005-08-09 19:47:14.000000000 -0700 +1 -1
@@ -1503,7 +1503,7 @@
 
 static inline int hwif_to_node(ide_hwif_t *hwif)
 {
-       if (hwif->pci_dev)
+       if (hwif && hwif->pci_dev)
                return pcibus_to_node(hwif->pci_dev->bus);
        else
                /* Add ways to determine the node of other busses here */
#4 lore raw
Quoted 1 line · Bartlomiej Zolnierkiewicz

hwif can't be NULL or something is *really* wrong

Ahh.. Yes.... Not enough time to think about this email properly since I need to get to the LWCE in SF. Wrong description. The oops was caused by pci_dev being NULL..

#5 lore raw
In reply to Christoph Lameter
Quoted 2 lines · Christoph Lameter

Correct. So we need to indeed go back to a version that does check for NULL that I initially proposed.

No, you need to fix the caller. "hwif_to_node(NULL)" is a nonsense operation rather like strlen(NULL). The caller need to be fixed.

#6 lore raw

Just to make sure to avoid all confusion. The title of this thread should be

"[PATCH] Fix ide-disk.c oops caused by hwif->pci_dev == NULL"

And this is the patch that was acknowledged by Andrew and that fixes the issue AFAIK. This patch needs to be included in 2.6.13. Lets make sure that we are all on the same page on this patch now:

---

From: Christoph Lameter <[email protected]>

There is one additional place where pcibus_to_node is used with the hwif that we did not cover.

- Move hwif_to_node to ide.h

- Use hwif_to_node in ide-disk.c

---

 drivers/ide/ide-disk.c  |    2 +-
 drivers/ide/ide-probe.c |    9 ---------
 include/linux/ide.h     |    9 +++++++++
 3 files changed, 10 insertions(+), 10 deletions(-)
drivers/ide/ide-disk.c renamed from drivers/ide/ide-disk.c~fix-ide-diskc-oops-caused-by-hwif-==-null +1 -1
diff -puN drivers/ide/ide-disk.c~fix-ide-diskc-oops-caused-by-hwif-==-null drivers/ide/ide-disk.c
@@ -1220,7 +1220,7 @@ static int ide_disk_probe(struct device 
 		goto failed;
 
 	g = alloc_disk_node(1 << PARTN_BITS,
-			pcibus_to_node(drive->hwif->pci_dev->bus));
+			hwif_to_node(drive->hwif));
 	if (!g)
 		goto out_free_idkp;
 
drivers/ide/ide-probe.c renamed from drivers/ide/ide-probe.c~fix-ide-diskc-oops-caused-by-hwif-==-null +0 -9
diff -puN drivers/ide/ide-probe.c~fix-ide-diskc-oops-caused-by-hwif-==-null drivers/ide/ide-probe.c
@@ -960,15 +960,6 @@ static void save_match(ide_hwif_t *hwif,
 }
 #endif /* MAX_HWIFS > 1 */
 
-static inline int hwif_to_node(ide_hwif_t *hwif)
-{
-	if (hwif->pci_dev)
-		return pcibus_to_node(hwif->pci_dev->bus);
-	else
-		/* Add ways to determine the node of other busses here */
-		return -1;
-}
-
 /*
  * init request queue
  */
include/linux/ide.h renamed from include/linux/ide.h~fix-ide-diskc-oops-caused-by-hwif-==-null +9 -0
diff -puN include/linux/ide.h~fix-ide-diskc-oops-caused-by-hwif-==-null include/linux/ide.h
@@ -1501,4 +1501,13 @@ extern struct bus_type ide_bus_type;
 #define ide_id_has_flush_cache_ext(id)	\
 	(((id)->cfs_enable_2 & 0x2400) == 0x2400)
 
+static inline int hwif_to_node(ide_hwif_t *hwif)
+{
+	if (hwif->pci_dev)
+		return pcibus_to_node(hwif->pci_dev->bus);
+	else
+		/* Add ways to determine the node of other busses here */
+		return -1;
+}
+
 #endif /* _IDE_H */

_