Skip to content

Commit 06118ae

Browse files
Dan Carpenterbroonie
authored andcommitted
regulator: max20086: Fix refcount leak in max20086_parse_regulators_dt()
There is a missing call to of_node_put() if devm_kcalloc() fails. Fix this by changing the code to use cleanup.h magic to drop the refcount. Fixes: 6b0cd72 ("regulator: max20086: fix invalid memory access") Signed-off-by: Dan Carpenter <[email protected]> Link: https://patch.msgid.link/[email protected] Reviewed-by: Laurent Pinchart <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 19272b3 commit 06118ae

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/regulator/max20086-regulator.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Copyright (C) 2022 Laurent Pinchart <[email protected]>
66
// Copyright (C) 2018 Avnet, Inc.
77

8+
#include <linux/cleanup.h>
89
#include <linux/err.h>
910
#include <linux/gpio/consumer.h>
1011
#include <linux/i2c.h>
@@ -133,11 +134,11 @@ static int max20086_regulators_register(struct max20086 *chip)
133134
static int max20086_parse_regulators_dt(struct max20086 *chip, bool *boot_on)
134135
{
135136
struct of_regulator_match *matches;
136-
struct device_node *node;
137137
unsigned int i;
138138
int ret;
139139

140-
node = of_get_child_by_name(chip->dev->of_node, "regulators");
140+
struct device_node *node __free(device_node) =
141+
of_get_child_by_name(chip->dev->of_node, "regulators");
141142
if (!node) {
142143
dev_err(chip->dev, "regulators node not found\n");
143144
return -ENODEV;
@@ -153,7 +154,6 @@ static int max20086_parse_regulators_dt(struct max20086 *chip, bool *boot_on)
153154

154155
ret = of_regulator_match(chip->dev, node, matches,
155156
chip->info->num_outputs);
156-
of_node_put(node);
157157
if (ret < 0) {
158158
dev_err(chip->dev, "Failed to match regulators\n");
159159
return -EINVAL;

0 commit comments

Comments
 (0)