Skip to contentSkip to conversation

PCI: fix pci_remove_legacy_files() crash

PATCH Applied MUNEDA Takahiro 3 participants 3 messages Feb 4, 2005 – Feb 8, 2005 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: fix pci_remove_legacy_files() crash

Hi,

The legacy_io which is the member of pci_bus struct might be NULL. It should be checked.

This patch checks 'b->legacy_io', NULL or not.

---

 probe.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
drivers/pci/probe.c +5 -3
diff -Npur a/drivers/pci/probe.c b/drivers/pci/probe.c
@@ -64,9 +64,11 @@ static void pci_create_legacy_files(stru
 
 void pci_remove_legacy_files(struct pci_bus *b)
 {
-	class_device_remove_bin_file(&b->class_dev, b->legacy_io);
-	class_device_remove_bin_file(&b->class_dev, b->legacy_mem);
-	kfree(b->legacy_io); /* both are allocated here */
+	if (b->legacy_io) {
+		class_device_remove_bin_file(&b->class_dev, b->legacy_io);
+		class_device_remove_bin_file(&b->class_dev, b->legacy_mem);
+		kfree(b->legacy_io); /* both are allocated here */
+	}
 }
 #else /* !HAVE_PCI_LEGACY */
 static inline void pci_create_legacy_files(struct pci_bus *bus) { return; }
Acked-by on v1 1/1
#1 lore raw
Quoted 32 lines · MUNEDA Takahiro

Hi,

The legacy_io which is the member of pci_bus struct might be NULL. It should be checked.

This patch checks 'b->legacy_io', NULL or not.

---

 probe.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff -Npur a/drivers/pci/probe.c b/drivers/pci/probe.c

drivers/pci/probe.c 2005-02-03 11:21:51.000000000 +0900 renamed from drivers/pci/probe.c 2005-01-31 13:31:27.000000000 +0900 +5 -3
@@ -64,9 +64,11 @@ static void pci_create_legacy_files(stru
 
 void pci_remove_legacy_files(struct pci_bus *b)
 {
- class_device_remove_bin_file(&b->class_dev, b->legacy_io);
- class_device_remove_bin_file(&b->class_dev, b->legacy_mem);
- kfree(b->legacy_io); /* both are allocated here */
+ if (b->legacy_io) {
+  class_device_remove_bin_file(&b->class_dev, b->legacy_io);
+  class_device_remove_bin_file(&b->class_dev, b->legacy_mem);
+  kfree(b->legacy_io); /* both are allocated here */
+ }
 }
 #else /* !HAVE_PCI_LEGACY */
 static inline void pci_create_legacy_files(struct pci_bus *bus) { return;
Quoted 1 line

}

Thanks, though the case where b->legacy_io is NULL should be very rare (it'll only happen if the initialization can't get memory for b->legacy_io), it's still a possibility so this fix is needed.