kernel/natapci - Fix a NULL pointer dereference.
authorAntonio Huete Jimenez <tuxillo@quantumachine.net>
Fri, 28 Feb 2014 13:16:02 +0000 (14:16 +0100)
committerAntonio Huete Jimenez <tuxillo@quantumachine.net>
Fri, 28 Feb 2014 17:44:30 +0000 (18:44 +0100)
- ata_devclass is NULL when no unit 0/1 is available or no
  legacy support has been detected.
- device_add_child() populates ata_devclass via make_device()
  so do not try to get information out of it when NULL.

Submitted-by: @dillon
sys/dev/disk/nata/ata-pci.c

index ec4be4f..6726d79 100644 (file)
@@ -246,9 +246,11 @@ ata_pci_attach(device_t dev)
            continue;
        }
        /* XXX TGEN devclass_find_free_unit() implementation */
-       while (freeunit < devclass_get_maxunit(ata_devclass) &&
-              devclass_get_device(ata_devclass, freeunit) != NULL)
-           freeunit++;
+       if (ata_devclass) {
+               while (freeunit < devclass_get_maxunit(ata_devclass) &&
+                   devclass_get_device(ata_devclass, freeunit) != NULL)
+                       freeunit++;
+       }
        device_add_child(dev, "ata", freeunit);
     }
     bus_generic_attach(dev);