driver core: Avoid NULL pointer dereferences in device_is_bound()
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 12 Jan 2016 00:51:44 +0000 (01:51 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 12 Jan 2016 00:51:44 +0000 (01:51 +0100)
If device_is_bound() is called on a device that's not been registered
yet, it will attepmt to dereference dev->p which is NULL, so avoid
that by checking dev->p in there against NULL.

Fixes: 6b9cb42752da "device core: add device_is_bound()"
Reported-and-tested-by: Guenter Roeck <linux@roeck-us.net>
Tested-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/base/dd.c

index 049942176b00abf76780bdc8bbe20fbc28de8ec8..c4da2df62e02525617a23ebe68fff4af0bb69350 100644 (file)
@@ -234,7 +234,7 @@ late_initcall(deferred_probe_initcall);
  */
 bool device_is_bound(struct device *dev)
 {
-       return klist_node_attached(&dev->p->knode_driver);
+       return dev->p && klist_node_attached(&dev->p->knode_driver);
 }
 
 static void driver_bound(struct device *dev)