Skip to content

Commit 4cbaba4

Browse files
andy-shevrafaeljw
authored andcommitted
ACPI: bus: Introduce acpi_dev_get() and reuse it in ACPI code
Introduce acpi_dev_get() to have a symmetrical API with acpi_dev_put() and reuse both in ACPI code in drivers/acpi/. While at it, use acpi_bus_put_acpi_device() in one place instead of the above. Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 0205055 commit 4cbaba4

4 files changed

Lines changed: 15 additions & 11 deletions

File tree

drivers/acpi/device_sysfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,12 @@ eject_store(struct device *d, struct device_attribute *attr,
376376
if (ACPI_FAILURE(status) || !acpi_device->flags.ejectable)
377377
return -ENODEV;
378378

379-
get_device(&acpi_device->dev);
379+
acpi_dev_get(acpi_device);
380380
status = acpi_hotplug_schedule(acpi_device, ACPI_OST_EC_OSPM_EJECT);
381381
if (ACPI_SUCCESS(status))
382382
return count;
383383

384-
put_device(&acpi_device->dev);
384+
acpi_dev_put(acpi_device);
385385
acpi_evaluate_ost(acpi_device->handle, ACPI_OST_EC_OSPM_EJECT,
386386
ACPI_OST_SC_NON_SPECIFIC_FAILURE, NULL);
387387
return status == AE_NO_MEMORY ? -ENOMEM : -EAGAIN;

drivers/acpi/glue.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)
190190
if (!acpi_dev)
191191
return -EINVAL;
192192

193-
get_device(&acpi_dev->dev);
193+
acpi_dev_get(acpi_dev);
194194
get_device(dev);
195195
physical_node = kzalloc(sizeof(*physical_node), GFP_KERNEL);
196196
if (!physical_node) {
@@ -217,7 +217,7 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)
217217
goto err;
218218

219219
put_device(dev);
220-
put_device(&acpi_dev->dev);
220+
acpi_dev_put(acpi_dev);
221221
return 0;
222222
}
223223
if (pn->node_id == node_id) {
@@ -257,7 +257,7 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)
257257
err:
258258
ACPI_COMPANION_SET(dev, NULL);
259259
put_device(dev);
260-
put_device(&acpi_dev->dev);
260+
acpi_dev_put(acpi_dev);
261261
return retval;
262262
}
263263
EXPORT_SYMBOL_GPL(acpi_bind_one);
@@ -285,7 +285,7 @@ int acpi_unbind_one(struct device *dev)
285285
ACPI_COMPANION_SET(dev, NULL);
286286
/* Drop references taken by acpi_bind_one(). */
287287
put_device(dev);
288-
put_device(&acpi_dev->dev);
288+
acpi_dev_put(acpi_dev);
289289
kfree(entry);
290290
break;
291291
}

drivers/acpi/scan.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ static void acpi_device_del_work_fn(struct work_struct *work_not_used)
530530
* used by the device.
531531
*/
532532
acpi_power_transition(adev, ACPI_STATE_D3_COLD);
533-
put_device(&adev->dev);
533+
acpi_dev_put(adev);
534534
}
535535
}
536536

@@ -604,8 +604,7 @@ EXPORT_SYMBOL(acpi_bus_get_device);
604604

605605
static void get_acpi_device(void *dev)
606606
{
607-
if (dev)
608-
get_device(&((struct acpi_device *)dev)->dev);
607+
acpi_dev_get(dev);
609608
}
610609

611610
struct acpi_device *acpi_bus_get_acpi_device(acpi_handle handle)
@@ -615,7 +614,7 @@ struct acpi_device *acpi_bus_get_acpi_device(acpi_handle handle)
615614

616615
void acpi_bus_put_acpi_device(struct acpi_device *adev)
617616
{
618-
put_device(&adev->dev);
617+
acpi_dev_put(adev);
619618
}
620619

621620
static struct acpi_device_bus_id *acpi_device_bus_id_match(const char *dev_id)
@@ -2355,7 +2354,7 @@ int __init acpi_scan_init(void)
23552354
acpi_detach_data(acpi_root->handle,
23562355
acpi_scan_drop_device);
23572356
acpi_device_del(acpi_root);
2358-
put_device(&acpi_root->dev);
2357+
acpi_bus_put_acpi_device(acpi_root);
23592358
goto out;
23602359
}
23612360
}

include/acpi/acpi_bus.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,11 @@ acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv);
694694
adev; \
695695
adev = acpi_dev_get_next_match_dev(adev, hid, uid, hrv))
696696

697+
static inline struct acpi_device *acpi_dev_get(struct acpi_device *adev)
698+
{
699+
return adev ? to_acpi_device(get_device(&adev->dev)) : NULL;
700+
}
701+
697702
static inline void acpi_dev_put(struct acpi_device *adev)
698703
{
699704
put_device(&adev->dev);

0 commit comments

Comments
 (0)