Skip to contentSkip to conversation

Be a bit defensive in quirk_nvidia_ck804() so we don't risk dereferencing a NULL pdev.

PATCH In review Jesper Juhl 3 participants 3 messages Dec 1, 2006 – Dec 2, 2006 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Be a bit defensive in quirk_nvidia_ck804() so we don't risk dereferencing a NULL pdev.

pci_get_slot() may return NULL if nothing was found. quirk_nvidia_ck804() does not check the value returned from pci_get_slot(), so it may end up causing a NULL pointer deref.

---

 drivers/pci/quirks.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/pci/quirks.c +2 -0
index 5b44838..d3dcbda 100644
@@ -1741,6 +1741,8 @@ static void __devinit quirk_nvidia_ck804
 	 * a single one having MSI is enough to be sure that MSI are supported.
 	 */
 	pdev = pci_get_slot(dev->bus, 0);
+	if (!pdev)
+		return;
 	if (dev->subordinate && !msi_ht_cap_enabled(dev)
 	    && !msi_ht_cap_enabled(pdev)) {
 		printk(KERN_WARNING "PCI: MSI quirk detected. "
Acked-by Alan Cox on v1 1/1
#1 lore raw
Quoted 6 lines · On Sat, 2 Dec 2006 00:21:56 +0100 Jesper Juhl <[email protected]> wrote:

pci_get_slot() may return NULL if nothing was found. quirk_nvidia_ck804() does not check the value returned from pci_get_slot(), so it may end up causing a NULL pointer deref.

I don't think its a physically possible case but it does no harm and it'll kill boot if it happens

#2 lore raw
In reply to Jesper Juhl
Quoted 4 lines · Jesper Juhl

pci_get_slot() may return NULL if nothing was found. quirk_nvidia_ck804() does not check the value returned from pci_get_slot(), so it may end up causing a NULL pointer deref.

Looks good. The possible NULL pointer is actually not at pci_dev_put, but rather at pci_find_capability on the msi_ht_cap_enabled(pdev) call.

Quoted 6 lines
drivers/pci/quirks.c +0 -0
index 5b44838..d3dcbda 100644

drivers/pci/quirks.c static void __devinit quirk_nvidia_ck804 · line 1748

Quoted 8 lines
drivers/pci/quirks.c +2 -0
@@ -1741,6 +1741,8 @@ static void __devinit quirk_nvidia_ck804
 	 * a single one having MSI is enough to be sure that MSI are supported.
 	 */
 	pdev = pci_get_slot(dev->bus, 0);
+	if (!pdev)
+		return;
 	if (dev->subordinate && !msi_ht_cap_enabled(dev)
 	    && !msi_ht_cap_enabled(pdev)) {
 		printk(KERN_WARNING "PCI: MSI quirk detected. "

The check for dev->subordinate in the neighboring conditional can also be removed.

David