From f8f47c1bd192ef079131c01b6a2842d24e3a1b12 Mon Sep 17 00:00:00 2001 From: Ard van Breemen Date: Thu, 11 Jan 2007 10:22:57 -0500 Subject: [PATCH] [PATCH] PCI: prevent down_read when pci_devices is empty The pci_find_subsys gets called very early by obsolete ide setup parameters. This is a bogus call since pci is not initialized yet, so the list is empty. But in the mean time, interrupts get enabled by down_read. This can result in a kernel panic when the irq controller gets initialized. This patch checks if the device list is empty before taking the semaphore, and hence will not enable irq's. Furthermore it will inform that it is called while pci_devices is empty as a reminder that the ide code needs to be fixed. The pci_get_subsys can get called in the same manner, and as such is patched in the same manner. [akpm@osdl.org: cleanups] Signed-off-by: Ard van Breemen Cc: Greg KH Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds [chrisw: fold in 6a4c24ec5212 to avoid printk spamming] Signed-off-by: Chris Wright --- drivers/pci/search.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/pci/search.c b/drivers/pci/search.c index 2f13eba5d5ae..0d492a54bdc3 100644 --- a/drivers/pci/search.c +++ b/drivers/pci/search.c @@ -193,6 +193,15 @@ static struct pci_dev * pci_find_subsys(unsigned int vendor, struct pci_dev *dev; WARN_ON(in_interrupt()); + + /* + * pci_find_subsys() can be called on the ide_setup() path, super-early + * in boot. But the down_read() will enable local interrupts, which + * can cause some machines to crash. So here we detect and flag that + * situation and bail out early. + */ + if (unlikely(list_empty(&pci_devices))) + return NULL; down_read(&pci_bus_sem); n = from ? from->global_list.next : pci_devices.next; @@ -259,6 +268,15 @@ pci_get_subsys(unsigned int vendor, unsigned int device, struct pci_dev *dev; WARN_ON(in_interrupt()); + + /* + * pci_get_subsys() can potentially be called by drivers super-early + * in boot. But the down_read() will enable local interrupts, which + * can cause some machines to crash. So here we detect and flag that + * situation and bail out early. + */ + if (unlikely(list_empty(&pci_devices))) + return NULL; down_read(&pci_bus_sem); n = from ? from->global_list.next : pci_devices.next; -- 2.39.5