ACPI: video: Use acpi_dev_for_each_child()
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 13 Jun 2022 18:26:28 +0000 (20:26 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 20 Jun 2022 18:33:13 +0000 (20:33 +0200)
Instead of walking the list of children of an ACPI device directly,
use acpi_dev_for_each_child() to carry out an action for all of
the given ACPI device's children.

This will help to eliminate the children list head from struct
acpi_device as it is redundant and it is used in questionable ways
in some places (in particular, locking is needed for walking the
list pointed to it safely, but it is often missing).

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
drivers/acpi/acpi_video.c

index e07782b1fbb68eb6ca3d7a7552387266519f1d83..7e3cab70b71829304a4c4ce4c0479ac75496213b 100644 (file)
@@ -1149,24 +1149,25 @@ acpi_video_get_device_type(struct acpi_video_bus *video,
        return 0;
 }
 
-static int
-acpi_video_bus_get_one_device(struct acpi_device *device,
-                             struct acpi_video_bus *video)
+static int acpi_video_bus_get_one_device(struct acpi_device *device, void *arg)
 {
-       unsigned long long device_id;
-       int status, device_type;
-       struct acpi_video_device *data;
+       struct acpi_video_bus *video = arg;
        struct acpi_video_device_attrib *attribute;
+       struct acpi_video_device *data;
+       unsigned long long device_id;
+       acpi_status status;
+       int device_type;
 
-       status =
-           acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
-       /* Some device omits _ADR, we skip them instead of fail */
+       status = acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
+       /* Skip devices without _ADR instead of failing. */
        if (ACPI_FAILURE(status))
-               return 0;
+               goto exit;
 
        data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
-       if (!data)
+       if (!data) {
+               dev_dbg(&device->dev, "Cannot attach\n");
                return -ENOMEM;
+       }
 
        strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
        strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
@@ -1226,7 +1227,9 @@ acpi_video_bus_get_one_device(struct acpi_device *device,
        list_add_tail(&data->entry, &video->video_device_list);
        mutex_unlock(&video->device_list_lock);
 
-       return status;
+exit:
+       video->child_count++;
+       return 0;
 }
 
 /*
@@ -1538,9 +1541,6 @@ static int
 acpi_video_bus_get_devices(struct acpi_video_bus *video,
                           struct acpi_device *device)
 {
-       int status = 0;
-       struct acpi_device *dev;
-
        /*
         * There are systems where video module known to work fine regardless
         * of broken _DOD and ignoring returned value here doesn't cause
@@ -1548,16 +1548,7 @@ acpi_video_bus_get_devices(struct acpi_video_bus *video,
         */
        acpi_video_device_enumerate(video);
 
-       list_for_each_entry(dev, &device->children, node) {
-
-               status = acpi_video_bus_get_one_device(dev, video);
-               if (status) {
-                       dev_err(&dev->dev, "Can't attach device\n");
-                       break;
-               }
-               video->child_count++;
-       }
-       return status;
+       return acpi_dev_for_each_child(device, acpi_video_bus_get_one_device, video);
 }
 
 /* acpi_video interface */