Skip to contentSkip to conversation

power/supply/olpc_battery: Hold the reference returned by of_find_compatible_node

PATCH In review Liang He 2 participants 2 messages Jun 21, 2022 – Jul 16, 2022 Power supply

lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH v2 1/1 power/supply/olpc_battery: Hold the reference returned by of_find_compatible_node

In olpc_battery_probe(), we should hold the reference returned by of_find_compatible_node() and use it to call of_node_put() for refcount balance.

---
changelog:

v2: fix bug intro-ed by v1, reported by lkp.
v1: add hold-ref code.

 drivers/power/supply/olpc_battery.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/power/supply/olpc_battery.c +4 -1
index e0476ec06601..a5da20ffd685 100644
@@ -635,6 +635,7 @@ static int olpc_battery_probe(struct platform_device *pdev)
 	struct power_supply_config bat_psy_cfg = {};
 	struct power_supply_config ac_psy_cfg = {};
 	struct olpc_battery_data *data;
+	struct device_node *np;
 	uint8_t status;
 	uint8_t ecver;
 	int ret;
@@ -649,7 +650,9 @@ static int olpc_battery_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	if (of_find_compatible_node(NULL, NULL, "olpc,xo1.75-ec")) {
+	np = of_find_compatible_node(NULL, NULL, "olpc,xo1.75-ec");
+	if (np) {
+		of_node_put(np);
 		/* XO 1.75 */
 		data->new_proto = true;
 		data->little_endian = true;
Signature · 1 line
2.25.1
#1 lore raw

Hi,

Quoted 6 lines · Liang He

In olpc_battery_probe(), we should hold the reference returned by of_find_compatible_node() and use it to call of_node_put() for refcount balance.

---

Thanks, queued.

-- Sebastian

Quoted 34 lines

changelog:

v2: fix bug intro-ed by v1, reported by lkp.
v1: add hold-ref code.

 drivers/power/supply/olpc_battery.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/power/supply/olpc_battery.c +4 -1
index e0476ec06601..a5da20ffd685 100644
@@ -635,6 +635,7 @@ static int olpc_battery_probe(struct platform_device *pdev)
 	struct power_supply_config bat_psy_cfg = {};
 	struct power_supply_config ac_psy_cfg = {};
 	struct olpc_battery_data *data;
+	struct device_node *np;
 	uint8_t status;
 	uint8_t ecver;
 	int ret;
@@ -649,7 +650,9 @@ static int olpc_battery_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	if (of_find_compatible_node(NULL, NULL, "olpc,xo1.75-ec")) {
+	np = of_find_compatible_node(NULL, NULL, "olpc,xo1.75-ec");
+	if (np) {
+		of_node_put(np);
 		/* XO 1.75 */
 		data->new_proto = true;
 		data->little_endian = true;
Signature · 1 line
2.25.1