ACPI / scan: Simplify ACPI driver probing
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 10 Jun 2013 11:00:50 +0000 (13:00 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Sat, 15 Jun 2013 22:36:06 +0000 (00:36 +0200)
There is no particular reason why acpi_bus_driver_init() needs to be
a separate function and its location with respect to its only caller,
acpi_device_probe(), makes the code a bit difficult to follow.

Besides, it doesn't really make sense to check if 'device' is not
NULL in acpi_bus_driver_init(), because we've already dereferenced
dev->driver in acpi_device_probe() at that point and, moreover,
'device' cannot be NULL then, because acpi_device_probe() is called
via really_probe() (which also sets dev->driver for that matter).

For these reasons, drop acpi_bus_driver_init() altogether and move
the remaining code from it directly into acpi_device_probe().

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/acpi/scan.c

index b14ac46948c9e444246eba50e367ed1a16399ea2..4eeea226245412e5ddfa1c147ea41440bf39ca9a 100644 (file)
@@ -816,32 +816,40 @@ static void acpi_device_remove_notify_handler(struct acpi_device *device)
                                           acpi_device_notify);
 }
 
-static int acpi_bus_driver_init(struct acpi_device *, struct acpi_driver *);
-static int acpi_device_probe(struct device * dev)
+static int acpi_device_probe(struct device *dev)
 {
        struct acpi_device *acpi_dev = to_acpi_device(dev);
        struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver);
        int ret;
 
-       ret = acpi_bus_driver_init(acpi_dev, acpi_drv);
-       if (!ret) {
-               if (acpi_drv->ops.notify) {
-                       ret = acpi_device_install_notify_handler(acpi_dev);
-                       if (ret) {
-                               if (acpi_drv->ops.remove)
-                                       acpi_drv->ops.remove(acpi_dev);
-                               acpi_dev->driver = NULL;
-                               acpi_dev->driver_data = NULL;
-                               return ret;
-                       }
-               }
+       if (!acpi_drv->ops.add)
+               return -ENOSYS;
 
-               ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-                       "Found driver [%s] for device [%s]\n",
-                       acpi_drv->name, acpi_dev->pnp.bus_id));
-               get_device(dev);
+       ret = acpi_drv->ops.add(acpi_dev);
+       if (ret)
+               return ret;
+
+       acpi_dev->driver = acpi_drv;
+       ACPI_DEBUG_PRINT((ACPI_DB_INFO,
+                         "Driver [%s] successfully bound to device [%s]\n",
+                         acpi_drv->name, acpi_dev->pnp.bus_id));
+
+       if (acpi_drv->ops.notify) {
+               ret = acpi_device_install_notify_handler(acpi_dev);
+               if (ret) {
+                       if (acpi_drv->ops.remove)
+                               acpi_drv->ops.remove(acpi_dev);
+
+                       acpi_dev->driver = NULL;
+                       acpi_dev->driver_data = NULL;
+                       return ret;
+               }
        }
-       return ret;
+
+       ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found driver [%s] for device [%s]\n",
+                         acpi_drv->name, acpi_dev->pnp.bus_id));
+       get_device(dev);
+       return 0;
 }
 
 static int acpi_device_remove(struct device * dev)
@@ -997,41 +1005,6 @@ static void acpi_device_unregister(struct acpi_device *device)
 /* --------------------------------------------------------------------------
                                  Driver Management
    -------------------------------------------------------------------------- */
-/**
- * acpi_bus_driver_init - add a device to a driver
- * @device: the device to add and initialize
- * @driver: driver for the device
- *
- * Used to initialize a device via its device driver.  Called whenever a
- * driver is bound to a device.  Invokes the driver's add() ops.
- */
-static int
-acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver)
-{
-       int result = 0;
-
-       if (!device || !driver)
-               return -EINVAL;
-
-       if (!driver->ops.add)
-               return -ENOSYS;
-
-       result = driver->ops.add(device);
-       if (result)
-               return result;
-
-       device->driver = driver;
-
-       /*
-        * TBD - Configuration Management: Assign resources to device based
-        * upon possible configuration and currently allocated resources.
-        */
-
-       ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-                         "Driver successfully bound to device\n"));
-       return 0;
-}
-
 /**
  * acpi_bus_register_driver - register a driver with the ACPI bus
  * @driver: driver being registered