ACPI: simplify building device HID/CID list
authorBjorn Helgaas <bjorn.helgaas@hp.com>
Mon, 21 Sep 2009 19:35:40 +0000 (13:35 -0600)
committerLen Brown <len.brown@intel.com>
Fri, 25 Sep 2009 19:09:49 +0000 (15:09 -0400)
Minor code cleanup, no functional change.  Instead of remembering
what HIDs & CIDs to add later, just add them immediately.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Len Brown <len.brown@intel.com>
drivers/acpi/scan.c

index da11b5379dc807786fbd6a5e547554da8db42a1e..468921bed22f4e33f9012592fe906c3ca9ba3a1d 100644 (file)
@@ -1016,21 +1016,19 @@ static void acpi_add_id(struct acpi_device *device, const char *dev_id)
 
 static void acpi_device_set_id(struct acpi_device *device)
 {
-       struct acpi_device_info *info = NULL;
-       char *hid = NULL;
-       struct acpica_device_id_list *cid_list = NULL;
-       char *cid_add = NULL;
        acpi_status status;
+       struct acpi_device_info *info;
+       struct acpica_device_id_list *cid_list;
        int i;
 
        switch (device->device_type) {
        case ACPI_BUS_TYPE_DEVICE:
                if (ACPI_IS_ROOT_DEVICE(device)) {
-                       hid = ACPI_SYSTEM_HID;
+                       acpi_add_id(device, ACPI_SYSTEM_HID);
                        break;
                } else if (ACPI_IS_ROOT_DEVICE(device->parent)) {
                        /* \_SB_, the only root-level namespace device */
-                       hid = ACPI_BUS_HID;
+                       acpi_add_id(device, ACPI_BUS_HID);
                        strcpy(device->pnp.device_name, ACPI_BUS_DEVICE_NAME);
                        strcpy(device->pnp.device_class, ACPI_BUS_CLASS);
                        break;
@@ -1043,41 +1041,43 @@ static void acpi_device_set_id(struct acpi_device *device)
                }
 
                if (info->valid & ACPI_VALID_HID)
-                       hid = info->hardware_id.string;
-               if (info->valid & ACPI_VALID_CID)
+                       acpi_add_id(device, info->hardware_id.string);
+               if (info->valid & ACPI_VALID_CID) {
                        cid_list = &info->compatible_id_list;
+                       for (i = 0; i < cid_list->count; i++)
+                               acpi_add_id(device, cid_list->ids[i].string);
+               }
                if (info->valid & ACPI_VALID_ADR) {
                        device->pnp.bus_address = info->address;
                        device->flags.bus_address = 1;
                }
 
-               /* If we have a video/bay/dock device, add our selfdefined
-                  HID to the CID list. Like that the video/bay/dock drivers
-                  will get autoloaded and the device might still match
-                  against another driver.
-               */
+               /*
+                * Some devices don't reliably have _HIDs & _CIDs, so add
+                * synthetic HIDs to make sure drivers can find them.
+                */
                if (acpi_is_video_device(device))
-                       cid_add = ACPI_VIDEO_HID;
+                       acpi_add_id(device, ACPI_VIDEO_HID);
                else if (ACPI_SUCCESS(acpi_bay_match(device)))
-                       cid_add = ACPI_BAY_HID;
+                       acpi_add_id(device, ACPI_BAY_HID);
                else if (ACPI_SUCCESS(acpi_dock_match(device)))
-                       cid_add = ACPI_DOCK_HID;
+                       acpi_add_id(device, ACPI_DOCK_HID);
 
                break;
        case ACPI_BUS_TYPE_POWER:
-               hid = ACPI_POWER_HID;
+               acpi_add_id(device, ACPI_POWER_HID);
                break;
        case ACPI_BUS_TYPE_PROCESSOR:
-               hid = ACPI_PROCESSOR_OBJECT_HID;
+               acpi_add_id(device, ACPI_PROCESSOR_OBJECT_HID);
                break;
        case ACPI_BUS_TYPE_THERMAL:
-               hid = ACPI_THERMAL_HID;
+               acpi_add_id(device, ACPI_THERMAL_HID);
                break;
        case ACPI_BUS_TYPE_POWER_BUTTON:
-               hid = ACPI_BUTTON_HID_POWERF;
+               acpi_add_id(device, ACPI_BUTTON_HID_POWERF);
                break;
        case ACPI_BUS_TYPE_SLEEP_BUTTON:
-               hid = ACPI_BUTTON_HID_SLEEPF;
+               acpi_add_id(device, ACPI_BUTTON_HID_SLEEPF);
                break;
        }
 
@@ -1088,18 +1088,8 @@ static void acpi_device_set_id(struct acpi_device *device)
         * This generic ID isn't useful for driver binding, but it provides
         * the useful property that "every acpi_device has an ID."
         */
-       if (!hid && !cid_list && !cid_add)
-               hid = "device";
-
-       if (hid)
-               acpi_add_id(device, hid);
-       if (cid_list)
-               for (i = 0; i < cid_list->count; i++)
-                       acpi_add_id(device, cid_list->ids[i].string);
-       if (cid_add)
-               acpi_add_id(device, cid_add);
-
-       kfree(info);
+       if (list_empty(&device->pnp.ids))
+               acpi_add_id(device, "device");
 }
 
 static int acpi_device_set_context(struct acpi_device *device)