aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-06-10 07:00:50 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-06-15 18:36:06 -0400
commitd9e455f53f6fb93c764de2399c3894bbdfd2caa7 (patch)
tree196ede4eac46fb8bab03791f0a12f1e7802ac95d
parent7d132055814ef17a6c7b69f342244c410a5e000f (diff)
ACPI / scan: Simplify ACPI driver probing
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>
-rw-r--r--drivers/acpi/scan.c81
1 files changed, 27 insertions, 54 deletions
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index b14ac46948c9..4eeea2262454 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -816,32 +816,40 @@ static void acpi_device_remove_notify_handler(struct acpi_device *device)
816 acpi_device_notify); 816 acpi_device_notify);
817} 817}
818 818
819static int acpi_bus_driver_init(struct acpi_device *, struct acpi_driver *); 819static int acpi_device_probe(struct device *dev)
820static int acpi_device_probe(struct device * dev)
821{ 820{
822 struct acpi_device *acpi_dev = to_acpi_device(dev); 821 struct acpi_device *acpi_dev = to_acpi_device(dev);
823 struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver); 822 struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver);
824 int ret; 823 int ret;
825 824
826 ret = acpi_bus_driver_init(acpi_dev, acpi_drv); 825 if (!acpi_drv->ops.add)
827 if (!ret) { 826 return -ENOSYS;
828 if (acpi_drv->ops.notify) {
829 ret = acpi_device_install_notify_handler(acpi_dev);
830 if (ret) {
831 if (acpi_drv->ops.remove)
832 acpi_drv->ops.remove(acpi_dev);
833 acpi_dev->driver = NULL;
834 acpi_dev->driver_data = NULL;
835 return ret;
836 }
837 }
838 827
839 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 828 ret = acpi_drv->ops.add(acpi_dev);
840 "Found driver [%s] for device [%s]\n", 829 if (ret)
841 acpi_drv->name, acpi_dev->pnp.bus_id)); 830 return ret;
842 get_device(dev); 831
832 acpi_dev->driver = acpi_drv;
833 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
834 "Driver [%s] successfully bound to device [%s]\n",
835 acpi_drv->name, acpi_dev->pnp.bus_id));
836
837 if (acpi_drv->ops.notify) {
838 ret = acpi_device_install_notify_handler(acpi_dev);
839 if (ret) {
840 if (acpi_drv->ops.remove)
841 acpi_drv->ops.remove(acpi_dev);
842
843 acpi_dev->driver = NULL;
844 acpi_dev->driver_data = NULL;
845 return ret;
846 }
843 } 847 }
844 return ret; 848
849 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found driver [%s] for device [%s]\n",
850 acpi_drv->name, acpi_dev->pnp.bus_id));
851 get_device(dev);
852 return 0;
845} 853}
846 854
847static int acpi_device_remove(struct device * dev) 855static int acpi_device_remove(struct device * dev)
@@ -998,41 +1006,6 @@ static void acpi_device_unregister(struct acpi_device *device)
998 Driver Management 1006 Driver Management
999 -------------------------------------------------------------------------- */ 1007 -------------------------------------------------------------------------- */
1000/** 1008/**
1001 * acpi_bus_driver_init - add a device to a driver
1002 * @device: the device to add and initialize
1003 * @driver: driver for the device
1004 *
1005 * Used to initialize a device via its device driver. Called whenever a
1006 * driver is bound to a device. Invokes the driver's add() ops.
1007 */
1008static int
1009acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver)
1010{
1011 int result = 0;
1012
1013 if (!device || !driver)
1014 return -EINVAL;
1015
1016 if (!driver->ops.add)
1017 return -ENOSYS;
1018
1019 result = driver->ops.add(device);
1020 if (result)
1021 return result;
1022
1023 device->driver = driver;
1024
1025 /*
1026 * TBD - Configuration Management: Assign resources to device based
1027 * upon possible configuration and currently allocated resources.
1028 */
1029
1030 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1031 "Driver successfully bound to device\n"));
1032 return 0;
1033}
1034
1035/**
1036 * acpi_bus_register_driver - register a driver with the ACPI bus 1009 * acpi_bus_register_driver - register a driver with the ACPI bus
1037 * @driver: driver being registered 1010 * @driver: driver being registered
1038 * 1011 *