mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1 0/2] thermal: testing: Simplifications related to thermal zone template reference counting
@ 2024-11-10 13:03 Rafael J. Wysocki
  2024-11-10 13:04 ` [PATCH v1 1/2] thermal: testing: Simplify tt_get_tt_zone() Rafael J. Wysocki
  2024-11-10 13:06 ` [PATCH v1 2/2] thermal: testing: Use DEFINE_FREE() and __free() to simplify code Rafael J. Wysocki
  0 siblings, 2 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2024-11-10 13:03 UTC (permalink / raw)
  To: Linux PM; +Cc: LKML, Lukasz Luba, Daniel Lezcano

Hi Everyone,

These simplify the thermal zone template reference counting implementation
a bit.

Thanks!




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v1 1/2] thermal: testing: Simplify tt_get_tt_zone()
  2024-11-10 13:03 [PATCH v1 0/2] thermal: testing: Simplifications related to thermal zone template reference counting Rafael J. Wysocki
@ 2024-11-10 13:04 ` Rafael J. Wysocki
  2024-11-10 13:06 ` [PATCH v1 2/2] thermal: testing: Use DEFINE_FREE() and __free() to simplify code Rafael J. Wysocki
  1 sibling, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2024-11-10 13:04 UTC (permalink / raw)
  To: Linux PM; +Cc: LKML, Lukasz Luba, Daniel Lezcano

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Notice that tt_get_tt_zone() need not use the ret variable in
the tt_thermal_zones list walk and make it return right after
incrementing the reference counter of the matching entry.

No functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/thermal/testing/zone.c |    9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

Index: linux-pm/drivers/thermal/testing/zone.c
===================================================================
--- linux-pm.orig/drivers/thermal/testing/zone.c
+++ linux-pm/drivers/thermal/testing/zone.c
@@ -288,19 +288,14 @@ static struct tt_thermal_zone *tt_get_tt
 
 	guard(mutex)(&tt_thermal_zones_lock);
 
-	ret = -EINVAL;
 	list_for_each_entry(tt_zone, &tt_thermal_zones, list_node) {
 		if (tt_zone->id == id) {
 			tt_zone->refcount++;
-			ret = 0;
-			break;
+			return tt_zone;
 		}
 	}
 
-	if (ret)
-		return ERR_PTR(ret);
-
-	return tt_zone;
+	return ERR_PTR(-EINVAL);
 }
 
 static void tt_put_tt_zone(struct tt_thermal_zone *tt_zone)




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v1 2/2] thermal: testing: Use DEFINE_FREE() and __free() to simplify code
  2024-11-10 13:03 [PATCH v1 0/2] thermal: testing: Simplifications related to thermal zone template reference counting Rafael J. Wysocki
  2024-11-10 13:04 ` [PATCH v1 1/2] thermal: testing: Simplify tt_get_tt_zone() Rafael J. Wysocki
@ 2024-11-10 13:06 ` Rafael J. Wysocki
  1 sibling, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2024-11-10 13:06 UTC (permalink / raw)
  To: Linux PM; +Cc: LKML, Lukasz Luba, Daniel Lezcano

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

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 <rafael.j.wysocki@intel.com>
---
 drivers/thermal/testing/zone.c |   24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

Index: linux-pm/drivers/thermal/testing/zone.c
===================================================================
--- linux-pm.orig/drivers/thermal/testing/zone.c
+++ linux-pm/drivers/thermal/testing/zone.c
@@ -305,6 +305,9 @@ static void tt_put_tt_zone(struct tt_the
 	tt_zone->refcount--;
 }
 
+DEFINE_FREE(put_tt_zone, struct tt_thermal_zone *,
+	    if (!IS_ERR_OR_NULL(_T)) tt_put_tt_zone(_T))
+
 static void tt_zone_add_trip_work_fn(struct work_struct *work)
 {
 	struct tt_work *tt_work = tt_work_of_work(work);
@@ -327,9 +330,9 @@ static void tt_zone_add_trip_work_fn(str
 
 int tt_zone_add_trip(const char *arg)
 {
+	struct tt_thermal_zone *tt_zone __free(put_tt_zone);
 	struct tt_work *tt_work __free(kfree);
 	struct tt_trip *tt_trip __free(kfree);
-	struct tt_thermal_zone *tt_zone;
 	int id;
 
 	tt_work = kzalloc(sizeof(*tt_work), GFP_KERNEL);
@@ -345,10 +348,8 @@ int tt_zone_add_trip(const char *arg)
 		return PTR_ERR(tt_zone);
 
 	id = ida_alloc(&tt_zone->ida, GFP_KERNEL);
-	if (id < 0) {
-		tt_put_tt_zone(tt_zone);
+	if (id < 0)
 		return id;
-	}
 
 	tt_trip->trip.type = THERMAL_TRIP_ACTIVE;
 	tt_trip->trip.temperature = THERMAL_TEMP_INVALID;
@@ -361,7 +362,7 @@ int tt_zone_add_trip(const char *arg)
 	tt_zone->num_trips++;
 
 	INIT_WORK(&tt_work->work, tt_zone_add_trip_work_fn);
-	tt_work->tt_zone = tt_zone;
+	tt_work->tt_zone = no_free_ptr(tt_zone);
 	tt_work->tt_trip = no_free_ptr(tt_trip);
 	schedule_work(&(no_free_ptr(tt_work)->work));
 
@@ -420,23 +421,18 @@ static int tt_zone_register_tz(struct tt
 
 int tt_zone_reg(const char *arg)
 {
-	struct tt_thermal_zone *tt_zone;
-	int ret;
+	struct tt_thermal_zone *tt_zone __free(put_tt_zone);
 
 	tt_zone = tt_get_tt_zone(arg);
 	if (IS_ERR(tt_zone))
 		return PTR_ERR(tt_zone);
 
-	ret = tt_zone_register_tz(tt_zone);
-
-	tt_put_tt_zone(tt_zone);
-
-	return ret;
+	return tt_zone_register_tz(tt_zone);
 }
 
 int tt_zone_unreg(const char *arg)
 {
-	struct tt_thermal_zone *tt_zone;
+	struct tt_thermal_zone *tt_zone __free(put_tt_zone);
 
 	tt_zone = tt_get_tt_zone(arg);
 	if (IS_ERR(tt_zone))
@@ -444,8 +440,6 @@ int tt_zone_unreg(const char *arg)
 
 	tt_zone_unregister_tz(tt_zone);
 
-	tt_put_tt_zone(tt_zone);
-
 	return 0;
 }
 




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-11-10 13:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-10 13:03 [PATCH v1 0/2] thermal: testing: Simplifications related to thermal zone template reference counting Rafael J. Wysocki
2024-11-10 13:04 ` [PATCH v1 1/2] thermal: testing: Simplify tt_get_tt_zone() Rafael J. Wysocki
2024-11-10 13:06 ` [PATCH v1 2/2] thermal: testing: Use DEFINE_FREE() and __free() to simplify code Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®