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

Configure Feed

Select the types of activity you want to include in your feed.

ACPI: TAD: Improve runtime PM using guard macros

Use guard pm_runtime_active_try to simplify runtime PM cleanup and
implement runtime resume error handling in multiple places.

Also use guard pm_runtime_noresume to simplify acpi_tad_remove().

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Link: https://patch.msgid.link/13881356.uLZWGnKmhe@rafael.j.wysocki

+38 -34
+38 -34
drivers/acpi/acpi_tad.c
··· 90 90 args[0].buffer.pointer = (u8 *)rt; 91 91 args[0].buffer.length = sizeof(*rt); 92 92 93 - pm_runtime_get_sync(dev); 93 + ACQUIRE(pm_runtime_active_try, pm)(dev); 94 + if (ACQUIRE_ERR(pm_runtime_active_try, &pm)) 95 + return -ENXIO; 94 96 95 97 status = acpi_evaluate_integer(handle, "_SRT", &arg_list, &retval); 96 - 97 - pm_runtime_put_sync(dev); 98 - 99 98 if (ACPI_FAILURE(status) || retval) 100 99 return -EIO; 101 100 102 101 return 0; 103 102 } 104 103 105 - static int acpi_tad_get_real_time(struct device *dev, struct acpi_tad_rt *rt) 104 + static int acpi_tad_evaluate_grt(struct device *dev, struct acpi_tad_rt *rt) 106 105 { 107 106 acpi_handle handle = ACPI_HANDLE(dev); 108 107 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER }; ··· 110 111 acpi_status status; 111 112 int ret = -EIO; 112 113 113 - pm_runtime_get_sync(dev); 114 - 115 114 status = acpi_evaluate_object(handle, "_GRT", NULL, &output); 116 - 117 - pm_runtime_put_sync(dev); 118 - 119 115 if (ACPI_FAILURE(status)) 120 116 goto out_free; 121 117 ··· 131 137 out_free: 132 138 ACPI_FREE(output.pointer); 133 139 return ret; 140 + } 141 + 142 + static int acpi_tad_get_real_time(struct device *dev, struct acpi_tad_rt *rt) 143 + { 144 + int ret; 145 + 146 + ACQUIRE(pm_runtime_active_try, pm)(dev); 147 + if (ACQUIRE_ERR(pm_runtime_active_try, &pm)) 148 + return -ENXIO; 149 + 150 + ret = acpi_tad_evaluate_grt(dev, rt); 151 + if (ret) 152 + return ret; 153 + 154 + return 0; 134 155 } 135 156 136 157 static char *acpi_tad_rt_next_field(char *s, int *val) ··· 275 266 args[0].integer.value = timer_id; 276 267 args[1].integer.value = value; 277 268 278 - pm_runtime_get_sync(dev); 269 + ACQUIRE(pm_runtime_active_try, pm)(dev); 270 + if (ACQUIRE_ERR(pm_runtime_active_try, &pm)) 271 + return -ENXIO; 279 272 280 273 status = acpi_evaluate_integer(handle, method, &arg_list, &retval); 281 - 282 - pm_runtime_put_sync(dev); 283 - 284 274 if (ACPI_FAILURE(status) || retval) 285 275 return -EIO; 286 276 ··· 322 314 323 315 args[0].integer.value = timer_id; 324 316 325 - pm_runtime_get_sync(dev); 317 + ACQUIRE(pm_runtime_active_try, pm)(dev); 318 + if (ACQUIRE_ERR(pm_runtime_active_try, &pm)) 319 + return -ENXIO; 326 320 327 321 status = acpi_evaluate_integer(handle, method, &arg_list, &retval); 328 - 329 - pm_runtime_put_sync(dev); 330 - 331 322 if (ACPI_FAILURE(status)) 332 323 return -EIO; 333 324 ··· 377 370 378 371 args[0].integer.value = timer_id; 379 372 380 - pm_runtime_get_sync(dev); 373 + ACQUIRE(pm_runtime_active_try, pm)(dev); 374 + if (ACQUIRE_ERR(pm_runtime_active_try, &pm)) 375 + return -ENXIO; 381 376 382 377 status = acpi_evaluate_integer(handle, "_CWS", &arg_list, &retval); 383 - 384 - pm_runtime_put_sync(dev); 385 - 386 378 if (ACPI_FAILURE(status) || retval) 387 379 return -EIO; 388 380 ··· 417 411 418 412 args[0].integer.value = timer_id; 419 413 420 - pm_runtime_get_sync(dev); 414 + ACQUIRE(pm_runtime_active_try, pm)(dev); 415 + if (ACQUIRE_ERR(pm_runtime_active_try, &pm)) 416 + return -ENXIO; 421 417 422 418 status = acpi_evaluate_integer(handle, "_GWS", &arg_list, &retval); 423 - 424 - pm_runtime_put_sync(dev); 425 - 426 419 if (ACPI_FAILURE(status)) 427 420 return -EIO; 428 421 ··· 576 571 577 572 sysfs_remove_group(&dev->kobj, &acpi_tad_attr_group); 578 573 579 - pm_runtime_get_noresume(dev); 580 - 581 - acpi_tad_disable_timer(dev, ACPI_TAD_AC_TIMER); 582 - acpi_tad_clear_status(dev, ACPI_TAD_AC_TIMER); 583 - if (dd->capabilities & ACPI_TAD_DC_WAKE) { 584 - acpi_tad_disable_timer(dev, ACPI_TAD_DC_TIMER); 585 - acpi_tad_clear_status(dev, ACPI_TAD_DC_TIMER); 574 + scoped_guard(pm_runtime_noresume, dev) { 575 + acpi_tad_disable_timer(dev, ACPI_TAD_AC_TIMER); 576 + acpi_tad_clear_status(dev, ACPI_TAD_AC_TIMER); 577 + if (dd->capabilities & ACPI_TAD_DC_WAKE) { 578 + acpi_tad_disable_timer(dev, ACPI_TAD_DC_TIMER); 579 + acpi_tad_clear_status(dev, ACPI_TAD_DC_TIMER); 580 + } 586 581 } 587 582 588 - pm_runtime_put_noidle(dev); 589 583 pm_runtime_suspend(dev); 590 584 pm_runtime_disable(dev); 591 585 acpi_remove_cmos_rtc_space_handler(handle);