Skip to content

Commit 62fcb99

Browse files
committed
ACPI: Drop parent field from struct acpi_device
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>
1 parent 6e1850b commit 62fcb99

File tree

14 files changed

+46
-37
lines changed

14 files changed

+46
-37
lines changed

drivers/acpi/acpi_amba.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static void amba_register_dummy_clk(void)
4848
static int amba_handler_attach(struct acpi_device *adev,
4949
const struct acpi_device_id *id)
5050
{
51+
struct acpi_device *parent = acpi_dev_parent(adev);
5152
struct amba_device *dev;
5253
struct resource_entry *rentry;
5354
struct list_head resource_list;
@@ -97,8 +98,8 @@ static int amba_handler_attach(struct acpi_device *adev,
9798
* attached to it, that physical device should be the parent of
9899
* the amba device we are about to create.
99100
*/
100-
if (adev->parent)
101-
dev->dev.parent = acpi_get_first_physical_node(adev->parent);
101+
if (parent)
102+
dev->dev.parent = acpi_get_first_physical_node(parent);
102103

103104
ACPI_COMPANION_SET(&dev->dev, adev);
104105

drivers/acpi/acpi_platform.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static void acpi_platform_fill_resource(struct acpi_device *adev,
7878
* If the device has parent we need to take its resources into
7979
* account as well because this device might consume part of those.
8080
*/
81-
parent = acpi_get_first_physical_node(adev->parent);
81+
parent = acpi_get_first_physical_node(acpi_dev_parent(adev));
8282
if (parent && dev_is_pci(parent))
8383
dest->parent = pci_find_resource(to_pci_dev(parent), dest);
8484
}
@@ -97,6 +97,7 @@ static void acpi_platform_fill_resource(struct acpi_device *adev,
9797
struct platform_device *acpi_create_platform_device(struct acpi_device *adev,
9898
const struct property_entry *properties)
9999
{
100+
struct acpi_device *parent = acpi_dev_parent(adev);
100101
struct platform_device *pdev = NULL;
101102
struct platform_device_info pdevinfo;
102103
struct resource_entry *rentry;
@@ -137,8 +138,7 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev,
137138
* attached to it, that physical device should be the parent of the
138139
* platform device we are about to create.
139140
*/
140-
pdevinfo.parent = adev->parent ?
141-
acpi_get_first_physical_node(adev->parent) : NULL;
141+
pdevinfo.parent = parent ? acpi_get_first_physical_node(parent) : NULL;
142142
pdevinfo.name = dev_name(&adev->dev);
143143
pdevinfo.id = -1;
144144
pdevinfo.res = resources;

drivers/acpi/acpi_video.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2030,7 +2030,7 @@ static int acpi_video_bus_add(struct acpi_device *device)
20302030
acpi_status status;
20312031

20322032
status = acpi_walk_namespace(ACPI_TYPE_DEVICE,
2033-
device->parent->handle, 1,
2033+
acpi_dev_parent(device)->handle, 1,
20342034
acpi_video_bus_match, NULL,
20352035
device, NULL);
20362036
if (status == AE_ALREADY_EXISTS) {

drivers/acpi/device_pm.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ static int acpi_dev_pm_explicit_get(struct acpi_device *device, int *state)
7474
*/
7575
int acpi_device_get_power(struct acpi_device *device, int *state)
7676
{
77+
struct acpi_device *parent = acpi_dev_parent(device);
7778
int result = ACPI_STATE_UNKNOWN;
7879
int error;
7980

@@ -82,8 +83,7 @@ int acpi_device_get_power(struct acpi_device *device, int *state)
8283

8384
if (!device->flags.power_manageable) {
8485
/* TBD: Non-recursive algorithm for walking up hierarchy. */
85-
*state = device->parent ?
86-
device->parent->power.state : ACPI_STATE_D0;
86+
*state = parent ? parent->power.state : ACPI_STATE_D0;
8787
goto out;
8888
}
8989

@@ -122,10 +122,10 @@ int acpi_device_get_power(struct acpi_device *device, int *state)
122122
* point, the fact that the device is in D0 implies that the parent has
123123
* to be in D0 too, except if ignore_parent is set.
124124
*/
125-
if (!device->power.flags.ignore_parent && device->parent
126-
&& device->parent->power.state == ACPI_STATE_UNKNOWN
127-
&& result == ACPI_STATE_D0)
128-
device->parent->power.state = ACPI_STATE_D0;
125+
if (!device->power.flags.ignore_parent && parent &&
126+
parent->power.state == ACPI_STATE_UNKNOWN &&
127+
result == ACPI_STATE_D0)
128+
parent->power.state = ACPI_STATE_D0;
129129

130130
*state = result;
131131

@@ -159,6 +159,7 @@ static int acpi_dev_pm_explicit_set(struct acpi_device *adev, int state)
159159
*/
160160
int acpi_device_set_power(struct acpi_device *device, int state)
161161
{
162+
struct acpi_device *parent = acpi_dev_parent(device);
162163
int target_state = state;
163164
int result = 0;
164165

@@ -191,12 +192,12 @@ int acpi_device_set_power(struct acpi_device *device, int state)
191192
return -ENODEV;
192193
}
193194

194-
if (!device->power.flags.ignore_parent && device->parent &&
195-
state < device->parent->power.state) {
195+
if (!device->power.flags.ignore_parent && parent &&
196+
state < parent->power.state) {
196197
acpi_handle_debug(device->handle,
197198
"Cannot transition to %s for parent in %s\n",
198199
acpi_power_state_string(state),
199-
acpi_power_state_string(device->parent->power.state));
200+
acpi_power_state_string(parent->power.state));
200201
return -ENODEV;
201202
}
202203

drivers/acpi/property.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,10 @@ static void acpi_init_of_compatible(struct acpi_device *adev)
304304
ret = acpi_dev_get_property(adev, "compatible",
305305
ACPI_TYPE_STRING, &of_compatible);
306306
if (ret) {
307-
if (adev->parent
308-
&& adev->parent->flags.of_compatible_ok)
307+
struct acpi_device *parent;
308+
309+
parent = acpi_dev_parent(adev);
310+
if (parent && parent->flags.of_compatible_ok)
309311
goto out;
310312

311313
return;

drivers/acpi/sbs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ static int acpi_sbs_add(struct acpi_device *device)
632632

633633
mutex_init(&sbs->lock);
634634

635-
sbs->hc = acpi_driver_data(device->parent);
635+
sbs->hc = acpi_driver_data(acpi_dev_parent(device));
636636
sbs->device = device;
637637
strcpy(acpi_device_name(device), ACPI_SBS_DEVICE_NAME);
638638
strcpy(acpi_device_class(device), ACPI_SBS_CLASS);

drivers/acpi/sbshc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ static int acpi_smbus_hc_add(struct acpi_device *device)
266266
mutex_init(&hc->lock);
267267
init_waitqueue_head(&hc->wait);
268268

269-
hc->ec = acpi_driver_data(device->parent);
269+
hc->ec = acpi_driver_data(acpi_dev_parent(device));
270270
hc->offset = (val >> 8) & 0xff;
271271
hc->query_bit = val & 0xff;
272272
device->driver_data = hc;

drivers/acpi/scan.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ extern struct acpi_device *acpi_root;
2929
#define ACPI_BUS_HID "LNXSYBUS"
3030
#define ACPI_BUS_DEVICE_NAME "System Bus"
3131

32-
#define ACPI_IS_ROOT_DEVICE(device) (!(device)->parent)
33-
3432
#define INVALID_ACPI_HANDLE ((acpi_handle)empty_zero_page)
3533

3634
static const char *dummy_hid = "device";
@@ -1110,7 +1108,7 @@ static void acpi_device_get_busid(struct acpi_device *device)
11101108
* The device's Bus ID is simply the object name.
11111109
* TBD: Shouldn't this value be unique (within the ACPI namespace)?
11121110
*/
1113-
if (ACPI_IS_ROOT_DEVICE(device)) {
1111+
if (!acpi_dev_parent(device)) {
11141112
strcpy(device->pnp.bus_id, "ACPI");
11151113
return;
11161114
}
@@ -1646,7 +1644,7 @@ static void acpi_init_coherency(struct acpi_device *adev)
16461644
{
16471645
unsigned long long cca = 0;
16481646
acpi_status status;
1649-
struct acpi_device *parent = adev->parent;
1647+
struct acpi_device *parent = acpi_dev_parent(adev);
16501648

16511649
if (parent && parent->flags.cca_seen) {
16521650
/*
@@ -1690,7 +1688,7 @@ static int acpi_check_serial_bus_slave(struct acpi_resource *ares, void *data)
16901688

16911689
static bool acpi_is_indirect_io_slave(struct acpi_device *device)
16921690
{
1693-
struct acpi_device *parent = device->parent;
1691+
struct acpi_device *parent = acpi_dev_parent(device);
16941692
static const struct acpi_device_id indirect_io_hosts[] = {
16951693
{"HISI0191", 0},
16961694
{}
@@ -1767,10 +1765,7 @@ void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
17671765
INIT_LIST_HEAD(&device->pnp.ids);
17681766
device->device_type = type;
17691767
device->handle = handle;
1770-
if (parent) {
1771-
device->parent = parent;
1772-
device->dev.parent = &parent->dev;
1773-
}
1768+
device->dev.parent = parent ? &parent->dev : NULL;
17741769
device->dev.release = release;
17751770
device->dev.bus = &acpi_bus_type;
17761771
fwnode_init(&device->fwnode, &acpi_device_fwnode_ops);
@@ -1867,8 +1862,8 @@ static int acpi_add_single_object(struct acpi_device **child,
18671862
acpi_device_add_finalize(device);
18681863

18691864
acpi_handle_debug(handle, "Added as %s, parent %s\n",
1870-
dev_name(&device->dev), device->parent ?
1871-
dev_name(&device->parent->dev) : "(null)");
1865+
dev_name(&device->dev), device->dev.parent ?
1866+
dev_name(device->dev.parent) : "(null)");
18721867

18731868
*child = device;
18741869
return 0;

drivers/hv/vmbus_drv.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2427,7 +2427,8 @@ static int vmbus_acpi_add(struct acpi_device *device)
24272427
* Some ancestor of the vmbus acpi device (Gen1 or Gen2
24282428
* firmware) is the VMOD that has the mmio ranges. Get that.
24292429
*/
2430-
for (ancestor = device->parent; ancestor; ancestor = ancestor->parent) {
2430+
for (ancestor = acpi_dev_parent(device); ancestor;
2431+
ancestor = acpi_dev_parent(ancestor)) {
24312432
result = acpi_walk_resources(ancestor->handle, METHOD_NAME__CRS,
24322433
vmbus_walk_resources, NULL);
24332434

drivers/perf/arm_dsu_pmu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ static int dsu_pmu_dt_get_cpus(struct device *dev, cpumask_t *mask)
639639
static int dsu_pmu_acpi_get_cpus(struct device *dev, cpumask_t *mask)
640640
{
641641
#ifdef CONFIG_ACPI
642+
struct acpi_device *parent_adev = acpi_dev_parent(ACPI_COMPANION(dev));
642643
int cpu;
643644

644645
/*
@@ -653,8 +654,7 @@ static int dsu_pmu_acpi_get_cpus(struct device *dev, cpumask_t *mask)
653654
continue;
654655

655656
acpi_dev = ACPI_COMPANION(cpu_dev);
656-
if (acpi_dev &&
657-
acpi_dev->parent == ACPI_COMPANION(dev)->parent)
657+
if (acpi_dev && acpi_dev_parent(acpi_dev) == parent_adev)
658658
cpumask_set_cpu(cpu, mask);
659659
}
660660
#endif

0 commit comments

Comments
 (0)