aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2012-12-20 18:36:49 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-01-03 07:09:40 -0500
commit0cd6ac52b333f66ee64e50ed216ec99231092dcd (patch)
tree6172c3977fe7d5ea3a9c04312ff19c3be28929a6
parent209d3b1743c8187c67cc75dbe9fefbcd3121fba0 (diff)
ACPI: Make acpi_bus_scan() and acpi_bus_add() take only one argument
The callers of acpi_bus_add() usually assume that if it has succeeded, then a struct acpi_device object has been attached to the handle passed as the first argument. Unfortunately, however, this assumption is wrong, because acpi_bus_scan(), and acpi_bus_add() too as a result, may return a pointer to a different struct acpi_device object on success (it may be an object corresponding to one of the descendant ACPI nodes in the namespace scope below that handle). For this reason, the callers of acpi_bus_add() who care about whether or not a struct acpi_device object has been created for its first argument need to check that using acpi_bus_get_device() anyway, so the second argument of acpi_bus_add() is not really useful for them. The same observation applies to acpi_bus_scan() executed directly from acpi_scan_init(). Therefore modify the relevant callers of acpi_bus_add() to check the existence of the struct acpi_device in question with the help of acpi_bus_get_device() and drop the no longer necessary second argument of acpi_bus_add(). Accordingly, modify acpi_scan_init() to use acpi_bus_get_device() to get acpi_root and drop the no longer needed second argument of acpi_bus_scan(). Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Acked-by: Yinghai Lu <yinghai@kernel.org> Acked-by: Toshi Kani <toshi.kani@hp.com>
-rw-r--r--drivers/acpi/acpi_memhotplug.c7
-rw-r--r--drivers/acpi/container.c7
-rw-r--r--drivers/acpi/dock.c4
-rw-r--r--drivers/acpi/processor_driver.c8
-rw-r--r--drivers/acpi/scan.c38
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c19
-rw-r--r--drivers/pci/hotplug/sgi_hotplug.c3
-rw-r--r--include/acpi/acpi_bus.h2
8 files changed, 45 insertions, 43 deletions
diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c
index d0a7da704d49..327ab4459558 100644
--- a/drivers/acpi/acpi_memhotplug.c
+++ b/drivers/acpi/acpi_memhotplug.c
@@ -167,11 +167,16 @@ acpi_memory_get_device(acpi_handle handle,
167 * Now add the notified device. This creates the acpi_device 167 * Now add the notified device. This creates the acpi_device
168 * and invokes .add function 168 * and invokes .add function
169 */ 169 */
170 result = acpi_bus_add(handle, &device); 170 result = acpi_bus_add(handle);
171 if (result) { 171 if (result) {
172 acpi_handle_warn(handle, "Cannot add acpi bus\n"); 172 acpi_handle_warn(handle, "Cannot add acpi bus\n");
173 return -EINVAL; 173 return -EINVAL;
174 } 174 }
175 result = acpi_bus_get_device(handle, &device);
176 if (result) {
177 acpi_handle_warn(handle, "Missing device object\n");
178 return -EINVAL;
179 }
175 180
176 end: 181 end:
177 *mem_device = acpi_driver_data(device); 182 *mem_device = acpi_driver_data(device);
diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c
index 0688f83bc436..f8fb2281f34a 100644
--- a/drivers/acpi/container.c
+++ b/drivers/acpi/container.c
@@ -166,11 +166,16 @@ static void container_notify_cb(acpi_handle handle, u32 type, void *context)
166 if (!ACPI_FAILURE(status) || device) 166 if (!ACPI_FAILURE(status) || device)
167 break; 167 break;
168 168
169 result = acpi_bus_add(handle, &device); 169 result = acpi_bus_add(handle);
170 if (result) { 170 if (result) {
171 acpi_handle_warn(handle, "Failed to add container\n"); 171 acpi_handle_warn(handle, "Failed to add container\n");
172 break; 172 break;
173 } 173 }
174 result = acpi_bus_get_device(handle, &device);
175 if (result) {
176 acpi_handle_warn(handle, "Missing device object\n");
177 break;
178 }
174 179
175 kobject_uevent(&device->dev.kobj, KOBJ_ONLINE); 180 kobject_uevent(&device->dev.kobj, KOBJ_ONLINE);
176 ost_code = ACPI_OST_SC_SUCCESS; 181 ost_code = ACPI_OST_SC_SUCCESS;
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index ff30582d2e1d..9e31b2bd93d3 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -317,9 +317,11 @@ static struct acpi_device * dock_create_acpi_device(acpi_handle handle)
317 * no device created for this object, 317 * no device created for this object,
318 * so we should create one. 318 * so we should create one.
319 */ 319 */
320 ret = acpi_bus_add(handle, &device); 320 ret = acpi_bus_add(handle);
321 if (ret) 321 if (ret)
322 pr_debug("error adding bus, %x\n", -ret); 322 pr_debug("error adding bus, %x\n", -ret);
323
324 acpi_bus_get_device(handle, &device);
323 } 325 }
324 return device; 326 return device;
325} 327}
diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
index 18b292e12b38..0777663f443e 100644
--- a/drivers/acpi/processor_driver.c
+++ b/drivers/acpi/processor_driver.c
@@ -699,12 +699,16 @@ static void acpi_processor_hotplug_notify(acpi_handle handle,
699 if (!acpi_bus_get_device(handle, &device)) 699 if (!acpi_bus_get_device(handle, &device))
700 break; 700 break;
701 701
702 result = acpi_bus_add(handle, &device); 702 result = acpi_bus_add(handle);
703 if (result) { 703 if (result) {
704 acpi_handle_err(handle, "Unable to add the device\n"); 704 acpi_handle_err(handle, "Unable to add the device\n");
705 break; 705 break;
706 } 706 }
707 707 result = acpi_bus_get_device(handle, &device);
708 if (result) {
709 acpi_handle_err(handle, "Missing device object\n");
710 break;
711 }
708 ost_code = ACPI_OST_SC_SUCCESS; 712 ost_code = ACPI_OST_SC_SUCCESS;
709 break; 713 break;
710 714
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index e3aed481aed2..3d44c705a3a2 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -1620,37 +1620,27 @@ static acpi_status acpi_bus_device_attach(acpi_handle handle, u32 lvl_not_used,
1620 return status; 1620 return status;
1621} 1621}
1622 1622
1623static int acpi_bus_scan(acpi_handle handle, struct acpi_device **child) 1623static int acpi_bus_scan(acpi_handle handle)
1624{ 1624{
1625 void *device = NULL; 1625 void *device = NULL;
1626 acpi_status status;
1627 int ret = -ENODEV;
1628 1626
1629 status = acpi_bus_check_add(handle, 0, NULL, &device); 1627 if (ACPI_SUCCESS(acpi_bus_check_add(handle, 0, NULL, &device)))
1630 if (ACPI_SUCCESS(status))
1631 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX, 1628 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
1632 acpi_bus_check_add, NULL, NULL, &device); 1629 acpi_bus_check_add, NULL, NULL, &device);
1633 1630
1634 if (!device) 1631 if (!device)
1635 goto out; 1632 return -ENODEV;
1636 1633
1637 ret = 0; 1634 if (ACPI_SUCCESS(acpi_bus_device_attach(handle, 0, NULL, NULL)))
1638 status = acpi_bus_device_attach(handle, 0, NULL, NULL);
1639 if (ACPI_SUCCESS(status))
1640 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX, 1635 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
1641 acpi_bus_device_attach, NULL, NULL, NULL); 1636 acpi_bus_device_attach, NULL, NULL, NULL);
1642 1637
1643 out: 1638 return 0;
1644 if (child)
1645 *child = device;
1646
1647 return ret;
1648} 1639}
1649 1640
1650/** 1641/**
1651 * acpi_bus_add - Add ACPI device node objects in a given namespace scope. 1642 * acpi_bus_add - Add ACPI device node objects in a given namespace scope.
1652 * @handle: Root of the namespace scope to scan. 1643 * @handle: Root of the namespace scope to scan.
1653 * @ret: Location to store a return struct acpi_device pointer.
1654 * 1644 *
1655 * Scan a given ACPI tree (probably recently hot-plugged) and create and add 1645 * Scan a given ACPI tree (probably recently hot-plugged) and create and add
1656 * found devices. 1646 * found devices.
@@ -1659,21 +1649,12 @@ static int acpi_bus_scan(acpi_handle handle, struct acpi_device **child)
1659 * there has been a real error. There just have been no suitable ACPI objects 1649 * there has been a real error. There just have been no suitable ACPI objects
1660 * in the table trunk from which the kernel could create a device and add an 1650 * in the table trunk from which the kernel could create a device and add an
1661 * appropriate driver. 1651 * appropriate driver.
1662 *
1663 * If 0 is returned, the memory location pointed to by @ret will be populated
1664 * with a pointer to a struct acpi_device created while scanning the namespace.
1665 * If @handle corresponds to a device node, that will be a pointer to the struct
1666 * acpi_device object corresponding to @handle. Otherwise, it will be a pointer
1667 * to a struct acpi_device corresponding to one of its descendants.
1668 *
1669 * If an error code is returned, NULL will be stored in the memory location
1670 * pointed to by @ret.
1671 */ 1652 */
1672int acpi_bus_add(acpi_handle handle, struct acpi_device **ret) 1653int acpi_bus_add(acpi_handle handle)
1673{ 1654{
1674 int err; 1655 int err;
1675 1656
1676 err = acpi_bus_scan(handle, ret); 1657 err = acpi_bus_scan(handle);
1677 if (err) 1658 if (err)
1678 return err; 1659 return err;
1679 1660
@@ -1777,8 +1758,11 @@ int __init acpi_scan_init(void)
1777 /* 1758 /*
1778 * Enumerate devices in the ACPI namespace. 1759 * Enumerate devices in the ACPI namespace.
1779 */ 1760 */
1780 result = acpi_bus_scan(ACPI_ROOT_OBJECT, &acpi_root); 1761 result = acpi_bus_scan(ACPI_ROOT_OBJECT);
1762 if (result)
1763 return result;
1781 1764
1765 result = acpi_bus_get_device(ACPI_ROOT_OBJECT, &acpi_root);
1782 if (!result) 1766 if (!result)
1783 result = acpi_bus_scan_fixed(); 1767 result = acpi_bus_scan_fixed();
1784 1768
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index dfc2df54b93a..91b5ad875c53 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -746,14 +746,13 @@ static int acpiphp_bus_add(struct acpiphp_func *func)
746 dbg("acpi_bus_trim return %x\n", ret_val); 746 dbg("acpi_bus_trim return %x\n", ret_val);
747 } 747 }
748 748
749 ret_val = acpi_bus_add(func->handle, &device); 749 ret_val = acpi_bus_add(func->handle);
750 if (ret_val) { 750 if (!ret_val)
751 dbg("error adding bus, %x\n", 751 ret_val = acpi_bus_get_device(func->handle, &device);
752 -ret_val); 752
753 goto acpiphp_bus_add_out; 753 if (ret_val)
754 } 754 dbg("error adding bus, %x\n", -ret_val);
755 755
756acpiphp_bus_add_out:
757 return ret_val; 756 return ret_val;
758} 757}
759 758
@@ -1130,10 +1129,14 @@ static void handle_bridge_insertion(acpi_handle handle, u32 type)
1130 return; 1129 return;
1131 } 1130 }
1132 1131
1133 if (acpi_bus_add(handle, &device)) { 1132 if (acpi_bus_add(handle)) {
1134 err("cannot add bridge to acpi list\n"); 1133 err("cannot add bridge to acpi list\n");
1135 return; 1134 return;
1136 } 1135 }
1136 if (acpi_bus_get_device(handle, &device)) {
1137 err("ACPI device object missing\n");
1138 return;
1139 }
1137 if (!acpiphp_configure_bridge(handle)) 1140 if (!acpiphp_configure_bridge(handle))
1138 add_bridge(handle); 1141 add_bridge(handle);
1139 else 1142 else
diff --git a/drivers/pci/hotplug/sgi_hotplug.c b/drivers/pci/hotplug/sgi_hotplug.c
index 801b58d1f78e..f3c419256d2a 100644
--- a/drivers/pci/hotplug/sgi_hotplug.c
+++ b/drivers/pci/hotplug/sgi_hotplug.c
@@ -412,7 +412,6 @@ static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
412 if (SN_ACPI_BASE_SUPPORT() && ssdt) { 412 if (SN_ACPI_BASE_SUPPORT() && ssdt) {
413 unsigned long long adr; 413 unsigned long long adr;
414 struct acpi_device *pdevice; 414 struct acpi_device *pdevice;
415 struct acpi_device *device;
416 acpi_handle phandle; 415 acpi_handle phandle;
417 acpi_handle chandle = NULL; 416 acpi_handle chandle = NULL;
418 acpi_handle rethandle; 417 acpi_handle rethandle;
@@ -448,7 +447,7 @@ static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
448 if (ACPI_SUCCESS(ret) && 447 if (ACPI_SUCCESS(ret) &&
449 (adr>>16) == (slot->device_num + 1)) { 448 (adr>>16) == (slot->device_num + 1)) {
450 449
451 ret = acpi_bus_add(chandle, &device); 450 ret = acpi_bus_add(chandle);
452 if (ACPI_FAILURE(ret)) { 451 if (ACPI_FAILURE(ret)) {
453 printk(KERN_ERR "%s: acpi_bus_add " 452 printk(KERN_ERR "%s: acpi_bus_add "
454 "failed (0x%x) for slot %d " 453 "failed (0x%x) for slot %d "
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 056cb0cd8eff..5e1d5a1b477f 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -351,7 +351,7 @@ static inline int acpi_bus_generate_proc_event(struct acpi_device *device, u8 ty
351#endif 351#endif
352int acpi_bus_register_driver(struct acpi_driver *driver); 352int acpi_bus_register_driver(struct acpi_driver *driver);
353void acpi_bus_unregister_driver(struct acpi_driver *driver); 353void acpi_bus_unregister_driver(struct acpi_driver *driver);
354int acpi_bus_add(acpi_handle handle, struct acpi_device **ret); 354int acpi_bus_add(acpi_handle handle);
355void acpi_bus_hot_remove_device(void *context); 355void acpi_bus_hot_remove_device(void *context);
356int acpi_bus_trim(struct acpi_device *start, int rmdevice); 356int acpi_bus_trim(struct acpi_device *start, int rmdevice);
357acpi_status acpi_bus_get_ejd(acpi_handle handle, acpi_handle * ejd); 357acpi_status acpi_bus_get_ejd(acpi_handle handle, acpi_handle * ejd);