ACPI: Drop parent field from struct acpi_device
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 24 Aug 2022 16:59:48 +0000 (18:59 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 24 Aug 2022 18:55:24 +0000 (20:55 +0200)
The parent field in struct acpi_device is, in fact, redundant,
because the dev.parent field in it effectively points to the same
object and it is used by the driver core.

Accordingly, the parent field can be dropped from struct acpi_device
and for this purpose define acpi_dev_parent() to retrieve a parent
struct acpi_device pointer from the dev.parent field in struct
acpi_device.  Next, update all of the users of the parent field
in struct acpi_device to use acpi_dev_parent() instead of it and
drop it.

While at it, drop the ACPI_IS_ROOT_DEVICE() macro that is only used
in one place in a confusing way.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Mark Brown <broonie@kernel.org>
Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: Wei Liu <wei.liu@kernel.org>
Reviewed-by: Punit Agrawal <punit.agrawal@bytedance.com>
14 files changed:
drivers/acpi/acpi_amba.c
drivers/acpi/acpi_platform.c
drivers/acpi/acpi_video.c
drivers/acpi/device_pm.c
drivers/acpi/property.c
drivers/acpi/sbs.c
drivers/acpi/sbshc.c
drivers/acpi/scan.c
drivers/hv/vmbus_drv.c
drivers/perf/arm_dsu_pmu.c
drivers/perf/qcom_l3_pmu.c
drivers/spi/spi.c
drivers/thunderbolt/acpi.c
include/acpi/acpi_bus.h

index ab8a4e0191b19c9ff5a87e8cb9c47b11cc51bc59..9d69546db2a4b244b0979588b0a44980adb69dad 100644 (file)
@@ -48,6 +48,7 @@ static void amba_register_dummy_clk(void)
 static int amba_handler_attach(struct acpi_device *adev,
                                const struct acpi_device_id *id)
 {
+       struct acpi_device *parent = acpi_dev_parent(adev);
        struct amba_device *dev;
        struct resource_entry *rentry;
        struct list_head resource_list;
@@ -97,8 +98,8 @@ static int amba_handler_attach(struct acpi_device *adev,
         * attached to it, that physical device should be the parent of
         * the amba device we are about to create.
         */
-       if (adev->parent)
-               dev->dev.parent = acpi_get_first_physical_node(adev->parent);
+       if (parent)
+               dev->dev.parent = acpi_get_first_physical_node(parent);
 
        ACPI_COMPANION_SET(&dev->dev, adev);
 
index de3cbf152deef1aebeac08fa784ff0272baaa36c..1a1c78b23fba383f59daeeb133615124c9fa02c6 100644 (file)
@@ -78,7 +78,7 @@ static void acpi_platform_fill_resource(struct acpi_device *adev,
         * If the device has parent we need to take its resources into
         * account as well because this device might consume part of those.
         */
-       parent = acpi_get_first_physical_node(adev->parent);
+       parent = acpi_get_first_physical_node(acpi_dev_parent(adev));
        if (parent && dev_is_pci(parent))
                dest->parent = pci_find_resource(to_pci_dev(parent), dest);
 }
@@ -97,6 +97,7 @@ static void acpi_platform_fill_resource(struct acpi_device *adev,
 struct platform_device *acpi_create_platform_device(struct acpi_device *adev,
                                                    const struct property_entry *properties)
 {
+       struct acpi_device *parent = acpi_dev_parent(adev);
        struct platform_device *pdev = NULL;
        struct platform_device_info pdevinfo;
        struct resource_entry *rentry;
@@ -137,8 +138,7 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev,
         * attached to it, that physical device should be the parent of the
         * platform device we are about to create.
         */
-       pdevinfo.parent = adev->parent ?
-               acpi_get_first_physical_node(adev->parent) : NULL;
+       pdevinfo.parent = parent ? acpi_get_first_physical_node(parent) : NULL;
        pdevinfo.name = dev_name(&adev->dev);
        pdevinfo.id = -1;
        pdevinfo.res = resources;
index 5cbe2196176db409e1f0c84407dceb27c9a40a18..92a6c6f9a9a7f29e9d4b6c12d6831efaf30b3837 100644 (file)
@@ -2030,7 +2030,7 @@ static int acpi_video_bus_add(struct acpi_device *device)
        acpi_status status;
 
        status = acpi_walk_namespace(ACPI_TYPE_DEVICE,
-                               device->parent->handle, 1,
+                               acpi_dev_parent(device)->handle, 1,
                                acpi_video_bus_match, NULL,
                                device, NULL);
        if (status == AE_ALREADY_EXISTS) {
index 2b7e08d54c3f0f55deb4ccf78b8069ffc553470e..028d8d14cd44d1179ccab49fd567b51e0690c218 100644 (file)
@@ -74,6 +74,7 @@ static int acpi_dev_pm_explicit_get(struct acpi_device *device, int *state)
  */
 int acpi_device_get_power(struct acpi_device *device, int *state)
 {
+       struct acpi_device *parent = acpi_dev_parent(device);
        int result = ACPI_STATE_UNKNOWN;
        int error;
 
@@ -82,8 +83,7 @@ int acpi_device_get_power(struct acpi_device *device, int *state)
 
        if (!device->flags.power_manageable) {
                /* TBD: Non-recursive algorithm for walking up hierarchy. */
-               *state = device->parent ?
-                       device->parent->power.state : ACPI_STATE_D0;
+               *state = parent ? parent->power.state : ACPI_STATE_D0;
                goto out;
        }
 
@@ -122,10 +122,10 @@ int acpi_device_get_power(struct acpi_device *device, int *state)
         * point, the fact that the device is in D0 implies that the parent has
         * to be in D0 too, except if ignore_parent is set.
         */
-       if (!device->power.flags.ignore_parent && device->parent
-           && device->parent->power.state == ACPI_STATE_UNKNOWN
-           && result == ACPI_STATE_D0)
-               device->parent->power.state = ACPI_STATE_D0;
+       if (!device->power.flags.ignore_parent && parent &&
+           parent->power.state == ACPI_STATE_UNKNOWN &&
+           result == ACPI_STATE_D0)
+               parent->power.state = ACPI_STATE_D0;
 
        *state = result;
 
@@ -159,6 +159,7 @@ static int acpi_dev_pm_explicit_set(struct acpi_device *adev, int state)
  */
 int acpi_device_set_power(struct acpi_device *device, int state)
 {
+       struct acpi_device *parent = acpi_dev_parent(device);
        int target_state = state;
        int result = 0;
 
@@ -191,12 +192,12 @@ int acpi_device_set_power(struct acpi_device *device, int state)
                return -ENODEV;
        }
 
-       if (!device->power.flags.ignore_parent && device->parent &&
-           state < device->parent->power.state) {
+       if (!device->power.flags.ignore_parent && parent &&
+           state < parent->power.state) {
                acpi_handle_debug(device->handle,
                                  "Cannot transition to %s for parent in %s\n",
                                  acpi_power_state_string(state),
-                                 acpi_power_state_string(device->parent->power.state));
+                                 acpi_power_state_string(parent->power.state));
                return -ENODEV;
        }
 
index 7b3ad8ed2f4e6c46ade0eb87ffa7754a0694c0eb..3dab3ac9c4a147744d32bb85195cc49ee37f7358 100644 (file)
@@ -304,8 +304,10 @@ static void acpi_init_of_compatible(struct acpi_device *adev)
                ret = acpi_dev_get_property(adev, "compatible",
                                            ACPI_TYPE_STRING, &of_compatible);
                if (ret) {
-                       if (adev->parent
-                           && adev->parent->flags.of_compatible_ok)
+                       struct acpi_device *parent;
+
+                       parent = acpi_dev_parent(adev);
+                       if (parent && parent->flags.of_compatible_ok)
                                goto out;
 
                        return;
index 4938010fcac78d821f828434a44e84389eff4539..e6a01a8df1b8150015f0f1931d338d72cc315183 100644 (file)
@@ -632,7 +632,7 @@ static int acpi_sbs_add(struct acpi_device *device)
 
        mutex_init(&sbs->lock);
 
-       sbs->hc = acpi_driver_data(device->parent);
+       sbs->hc = acpi_driver_data(acpi_dev_parent(device));
        sbs->device = device;
        strcpy(acpi_device_name(device), ACPI_SBS_DEVICE_NAME);
        strcpy(acpi_device_class(device), ACPI_SBS_CLASS);
index 7c62e149a7a16fa5287928511c082b8887cfcda9..340e0b61587e02c4e8218d31907f4b39876fe3a0 100644 (file)
@@ -266,7 +266,7 @@ static int acpi_smbus_hc_add(struct acpi_device *device)
        mutex_init(&hc->lock);
        init_waitqueue_head(&hc->wait);
 
-       hc->ec = acpi_driver_data(device->parent);
+       hc->ec = acpi_driver_data(acpi_dev_parent(device));
        hc->offset = (val >> 8) & 0xff;
        hc->query_bit = val & 0xff;
        device->driver_data = hc;
index 0d9c350608bf0a5946023b1d5039382ddd5bd6ad..f6b9ea937de1bea402d7c5bfbf093d2ee08c3645 100644 (file)
@@ -29,8 +29,6 @@ extern struct acpi_device *acpi_root;
 #define ACPI_BUS_HID                   "LNXSYBUS"
 #define ACPI_BUS_DEVICE_NAME           "System Bus"
 
-#define ACPI_IS_ROOT_DEVICE(device)    (!(device)->parent)
-
 #define INVALID_ACPI_HANDLE    ((acpi_handle)empty_zero_page)
 
 static const char *dummy_hid = "device";
@@ -1110,7 +1108,7 @@ static void acpi_device_get_busid(struct acpi_device *device)
         * The device's Bus ID is simply the object name.
         * TBD: Shouldn't this value be unique (within the ACPI namespace)?
         */
-       if (ACPI_IS_ROOT_DEVICE(device)) {
+       if (!acpi_dev_parent(device)) {
                strcpy(device->pnp.bus_id, "ACPI");
                return;
        }
@@ -1646,7 +1644,7 @@ static void acpi_init_coherency(struct acpi_device *adev)
 {
        unsigned long long cca = 0;
        acpi_status status;
-       struct acpi_device *parent = adev->parent;
+       struct acpi_device *parent = acpi_dev_parent(adev);
 
        if (parent && parent->flags.cca_seen) {
                /*
@@ -1690,7 +1688,7 @@ static int acpi_check_serial_bus_slave(struct acpi_resource *ares, void *data)
 
 static bool acpi_is_indirect_io_slave(struct acpi_device *device)
 {
-       struct acpi_device *parent = device->parent;
+       struct acpi_device *parent = acpi_dev_parent(device);
        static const struct acpi_device_id indirect_io_hosts[] = {
                {"HISI0191", 0},
                {}
@@ -1767,10 +1765,7 @@ void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
        INIT_LIST_HEAD(&device->pnp.ids);
        device->device_type = type;
        device->handle = handle;
-       if (parent) {
-               device->parent = parent;
-               device->dev.parent = &parent->dev;
-       }
+       device->dev.parent = parent ? &parent->dev : NULL;
        device->dev.release = release;
        device->dev.bus = &acpi_bus_type;
        fwnode_init(&device->fwnode, &acpi_device_fwnode_ops);
@@ -1867,8 +1862,8 @@ static int acpi_add_single_object(struct acpi_device **child,
        acpi_device_add_finalize(device);
 
        acpi_handle_debug(handle, "Added as %s, parent %s\n",
-                         dev_name(&device->dev), device->parent ?
-                               dev_name(&device->parent->dev) : "(null)");
+                         dev_name(&device->dev), device->dev.parent ?
+                               dev_name(device->dev.parent) : "(null)");
 
        *child = device;
        return 0;
index 23c680d1a0f5415735f2ba9d99ec47500a7fbe44..c905d40964cbd6989b998eb17f6ff2404da5285c 100644 (file)
@@ -2427,7 +2427,8 @@ static int vmbus_acpi_add(struct acpi_device *device)
         * Some ancestor of the vmbus acpi device (Gen1 or Gen2
         * firmware) is the VMOD that has the mmio ranges. Get that.
         */
-       for (ancestor = device->parent; ancestor; ancestor = ancestor->parent) {
+       for (ancestor = acpi_dev_parent(device); ancestor;
+            ancestor = acpi_dev_parent(ancestor)) {
                result = acpi_walk_resources(ancestor->handle, METHOD_NAME__CRS,
                                             vmbus_walk_resources, NULL);
 
index a36698a90d2f2640014426edfff60c452ad5e96d..4a15c86f45efbf1a09b46915eb768d7258d07e1a 100644 (file)
@@ -639,6 +639,7 @@ static int dsu_pmu_dt_get_cpus(struct device *dev, cpumask_t *mask)
 static int dsu_pmu_acpi_get_cpus(struct device *dev, cpumask_t *mask)
 {
 #ifdef CONFIG_ACPI
+       struct acpi_device *parent_adev = acpi_dev_parent(ACPI_COMPANION(dev));
        int cpu;
 
        /*
@@ -653,8 +654,7 @@ static int dsu_pmu_acpi_get_cpus(struct device *dev, cpumask_t *mask)
                        continue;
 
                acpi_dev = ACPI_COMPANION(cpu_dev);
-               if (acpi_dev &&
-                       acpi_dev->parent == ACPI_COMPANION(dev)->parent)
+               if (acpi_dev && acpi_dev_parent(acpi_dev) == parent_adev)
                        cpumask_set_cpu(cpu, mask);
        }
 #endif
index 1ff2ff6582bf86808a107876c2b2473b64df24a9..346311a05460b240ef33228eb5cb067eab00bb25 100644 (file)
@@ -742,7 +742,8 @@ static int qcom_l3_cache_pmu_probe(struct platform_device *pdev)
 
        l3pmu = devm_kzalloc(&pdev->dev, sizeof(*l3pmu), GFP_KERNEL);
        name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "l3cache_%s_%s",
-                     acpi_dev->parent->pnp.unique_id, acpi_dev->pnp.unique_id);
+                     acpi_dev_parent(acpi_dev)->pnp.unique_id,
+                     acpi_dev->pnp.unique_id);
        if (!l3pmu || !name)
                return -ENOMEM;
 
index 83da8862b8f22ee414bc7f92af8550285e43e4d1..58302259a5e34f1b522e9cbaff33bee65d2be102 100644 (file)
@@ -4375,7 +4375,7 @@ static int acpi_spi_notify(struct notifier_block *nb, unsigned long value,
 
        switch (value) {
        case ACPI_RECONFIG_DEVICE_ADD:
-               ctlr = acpi_spi_find_controller_by_adev(adev->parent);
+               ctlr = acpi_spi_find_controller_by_adev(acpi_dev_parent(adev));
                if (!ctlr)
                        break;
 
index b1f0dc8df47cde840a403f62699b9f5326b72c06..7a8adf5ad5a09d66032b32b06bea154e8a745368 100644 (file)
@@ -42,7 +42,7 @@ static acpi_status tb_acpi_add_link(acpi_handle handle, u32 level, void *data,
         */
        dev = acpi_get_first_physical_node(adev);
        while (!dev) {
-               adev = adev->parent;
+               adev = acpi_dev_parent(adev);
                if (!adev)
                        break;
                dev = acpi_get_first_physical_node(adev);
index 7ff067a5a3bd310741f78d657ef7b56cdba4323c..6289020fdab86bcd9f86ca2cbcd89fae6f1adfc9 100644 (file)
@@ -365,7 +365,6 @@ struct acpi_device {
        int device_type;
        acpi_handle handle;             /* no handle for fixed hardware */
        struct fwnode_handle fwnode;
-       struct acpi_device *parent;
        struct list_head wakeup_list;
        struct list_head del_list;
        struct acpi_device_status status;
@@ -458,6 +457,14 @@ static inline void *acpi_driver_data(struct acpi_device *d)
 #define to_acpi_device(d)      container_of(d, struct acpi_device, dev)
 #define to_acpi_driver(d)      container_of(d, struct acpi_driver, drv)
 
+static inline struct acpi_device *acpi_dev_parent(struct acpi_device *adev)
+{
+       if (adev->dev.parent)
+               return to_acpi_device(adev->dev.parent);
+
+       return NULL;
+}
+
 static inline void acpi_set_device_status(struct acpi_device *adev, u32 sta)
 {
        *((u32 *)&adev->status) = sta;
@@ -478,6 +485,7 @@ void acpi_initialize_hp_context(struct acpi_device *adev,
 /* acpi_device.dev.bus == &acpi_bus_type */
 extern struct bus_type acpi_bus_type;
 
+struct acpi_device *acpi_dev_parent(struct acpi_device *adev);
 int acpi_bus_for_each_dev(int (*fn)(struct device *, void *), void *data);
 int acpi_dev_for_each_child(struct acpi_device *adev,
                            int (*fn)(struct acpi_device *, void *), void *data);