Skip to content

Commit 1c426fd

Browse files
committed
thermal: testing: Use DEFINE_FREE() and __free() to simplify code
Use DEFINE_FREE() to define a __free function for dropping thermal zone template reference counters and use it along with __free() to simplify code in some places. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <[email protected]> Link: https://patch.msgid.link/[email protected] [ rjw: Add variable initialization to address compiler warning ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 9782dd1 commit 1c426fd

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

drivers/thermal/testing/zone.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ static void tt_put_tt_zone(struct tt_thermal_zone *tt_zone)
305305
tt_zone->refcount--;
306306
}
307307

308+
DEFINE_FREE(put_tt_zone, struct tt_thermal_zone *,
309+
if (!IS_ERR_OR_NULL(_T)) tt_put_tt_zone(_T))
310+
308311
static void tt_zone_add_trip_work_fn(struct work_struct *work)
309312
{
310313
struct tt_work *tt_work = tt_work_of_work(work);
@@ -327,9 +330,9 @@ static void tt_zone_add_trip_work_fn(struct work_struct *work)
327330

328331
int tt_zone_add_trip(const char *arg)
329332
{
333+
struct tt_thermal_zone *tt_zone __free(put_tt_zone) = NULL;
330334
struct tt_work *tt_work __free(kfree);
331335
struct tt_trip *tt_trip __free(kfree);
332-
struct tt_thermal_zone *tt_zone;
333336
int id;
334337

335338
tt_work = kzalloc(sizeof(*tt_work), GFP_KERNEL);
@@ -345,10 +348,8 @@ int tt_zone_add_trip(const char *arg)
345348
return PTR_ERR(tt_zone);
346349

347350
id = ida_alloc(&tt_zone->ida, GFP_KERNEL);
348-
if (id < 0) {
349-
tt_put_tt_zone(tt_zone);
351+
if (id < 0)
350352
return id;
351-
}
352353

353354
tt_trip->trip.type = THERMAL_TRIP_ACTIVE;
354355
tt_trip->trip.temperature = THERMAL_TEMP_INVALID;
@@ -361,7 +362,7 @@ int tt_zone_add_trip(const char *arg)
361362
tt_zone->num_trips++;
362363

363364
INIT_WORK(&tt_work->work, tt_zone_add_trip_work_fn);
364-
tt_work->tt_zone = tt_zone;
365+
tt_work->tt_zone = no_free_ptr(tt_zone);
365366
tt_work->tt_trip = no_free_ptr(tt_trip);
366367
schedule_work(&(no_free_ptr(tt_work)->work));
367368

@@ -420,32 +421,25 @@ static int tt_zone_register_tz(struct tt_thermal_zone *tt_zone)
420421

421422
int tt_zone_reg(const char *arg)
422423
{
423-
struct tt_thermal_zone *tt_zone;
424-
int ret;
424+
struct tt_thermal_zone *tt_zone __free(put_tt_zone);
425425

426426
tt_zone = tt_get_tt_zone(arg);
427427
if (IS_ERR(tt_zone))
428428
return PTR_ERR(tt_zone);
429429

430-
ret = tt_zone_register_tz(tt_zone);
431-
432-
tt_put_tt_zone(tt_zone);
433-
434-
return ret;
430+
return tt_zone_register_tz(tt_zone);
435431
}
436432

437433
int tt_zone_unreg(const char *arg)
438434
{
439-
struct tt_thermal_zone *tt_zone;
435+
struct tt_thermal_zone *tt_zone __free(put_tt_zone);
440436

441437
tt_zone = tt_get_tt_zone(arg);
442438
if (IS_ERR(tt_zone))
443439
return PTR_ERR(tt_zone);
444440

445441
tt_zone_unregister_tz(tt_zone);
446442

447-
tt_put_tt_zone(tt_zone);
448-
449443
return 0;
450444
}
451445

0 commit comments

Comments
 (0)