@@ -8,6 +8,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+#include <linux/cleanup.h>
#include <linux/err.h>
#include <linux/export.h>
#include <linux/of.h>
@@ -22,11 +23,9 @@
static int of_find_trip_id(struct device_node *np, struct device_node *trip)
{
- struct device_node *trips;
- struct device_node *t;
int i = 0;
- trips = of_get_child_by_name(np, "trips");
+ struct device_node *trips __free(device_node) = of_get_child_by_name(np, "trips");
if (!trips) {
pr_err("Failed to find 'trips' node\n");
return -EINVAL;
@@ -35,20 +34,13 @@ static int of_find_trip_id(struct device_node *np, struct device_node *trip)
/*
* Find the trip id point associated with the cooling device map
*/
- for_each_child_of_node(trips, t) {
-
- if (t == trip) {
- of_node_put(t);
- goto out;
- }
+ for_each_child_of_node_scoped(trips, t) {
+ if (t == trip)
+ return i;
i++;
}
- i = -ENXIO;
-out:
- of_node_put(trips);
-
- return i;
+ return -ENXIO;
}
/*