Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Andy Shevchenko and committed by
Rafael J. Wysocki
4cbaba4e 02050558

+15 -11
+2 -2
drivers/acpi/device_sysfs.c
··· 376 376 if (ACPI_FAILURE(status) || !acpi_device->flags.ejectable) 377 377 return -ENODEV; 378 378 379 - get_device(&acpi_device->dev); 379 + acpi_dev_get(acpi_device); 380 380 status = acpi_hotplug_schedule(acpi_device, ACPI_OST_EC_OSPM_EJECT); 381 381 if (ACPI_SUCCESS(status)) 382 382 return count; 383 383 384 - put_device(&acpi_device->dev); 384 + acpi_dev_put(acpi_device); 385 385 acpi_evaluate_ost(acpi_device->handle, ACPI_OST_EC_OSPM_EJECT, 386 386 ACPI_OST_SC_NON_SPECIFIC_FAILURE, NULL); 387 387 return status == AE_NO_MEMORY ? -ENOMEM : -EAGAIN;
+4 -4
drivers/acpi/glue.c
··· 190 190 if (!acpi_dev) 191 191 return -EINVAL; 192 192 193 - get_device(&acpi_dev->dev); 193 + acpi_dev_get(acpi_dev); 194 194 get_device(dev); 195 195 physical_node = kzalloc(sizeof(*physical_node), GFP_KERNEL); 196 196 if (!physical_node) { ··· 217 217 goto err; 218 218 219 219 put_device(dev); 220 - put_device(&acpi_dev->dev); 220 + acpi_dev_put(acpi_dev); 221 221 return 0; 222 222 } 223 223 if (pn->node_id == node_id) { ··· 257 257 err: 258 258 ACPI_COMPANION_SET(dev, NULL); 259 259 put_device(dev); 260 - put_device(&acpi_dev->dev); 260 + acpi_dev_put(acpi_dev); 261 261 return retval; 262 262 } 263 263 EXPORT_SYMBOL_GPL(acpi_bind_one); ··· 285 285 ACPI_COMPANION_SET(dev, NULL); 286 286 /* Drop references taken by acpi_bind_one(). */ 287 287 put_device(dev); 288 - put_device(&acpi_dev->dev); 288 + acpi_dev_put(acpi_dev); 289 289 kfree(entry); 290 290 break; 291 291 }
+4 -5
drivers/acpi/scan.c
··· 530 530 * used by the device. 531 531 */ 532 532 acpi_power_transition(adev, ACPI_STATE_D3_COLD); 533 - put_device(&adev->dev); 533 + acpi_dev_put(adev); 534 534 } 535 535 } 536 536 ··· 604 604 605 605 static void get_acpi_device(void *dev) 606 606 { 607 - if (dev) 608 - get_device(&((struct acpi_device *)dev)->dev); 607 + acpi_dev_get(dev); 609 608 } 610 609 611 610 struct acpi_device *acpi_bus_get_acpi_device(acpi_handle handle) ··· 614 615 615 616 void acpi_bus_put_acpi_device(struct acpi_device *adev) 616 617 { 617 - put_device(&adev->dev); 618 + acpi_dev_put(adev); 618 619 } 619 620 620 621 static struct acpi_device_bus_id *acpi_device_bus_id_match(const char *dev_id) ··· 2354 2355 acpi_detach_data(acpi_root->handle, 2355 2356 acpi_scan_drop_device); 2356 2357 acpi_device_del(acpi_root); 2357 - put_device(&acpi_root->dev); 2358 + acpi_bus_put_acpi_device(acpi_root); 2358 2359 goto out; 2359 2360 } 2360 2361 }
+5
include/acpi/acpi_bus.h
··· 694 694 adev; \ 695 695 adev = acpi_dev_get_next_match_dev(adev, hid, uid, hrv)) 696 696 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 + 697 702 static inline void acpi_dev_put(struct acpi_device *adev) 698 703 { 699 704 put_device(&adev->dev);