Skip to content

Commit 82c5ada

Browse files
javiercarrascocruzlag-linaro
authored andcommitted
leds: pca995x: Fix device child node usage in pca995x_probe()
The current implementation accesses the `child` fwnode handle outside of device_for_each_child_node() without incrementing its refcount. Add the missing call to `fwnode_handle_get(child)`. The cleanup process where `child` is accessed is not right either because a single call to `fwnode_handle_put()` is carried out in case of an error, ignoring unasigned nodes at the point when the error happens. Keep `child` inside of the first loop, and use the helper pointer that receives references via `fwnode_handle_get()` to handle the child nodes within the second loop. Keeping `child` inside the first node has also the advantage that the scoped version of the loop can be used. Fixes: ee4e80b ("leds: pca995x: Add support for PCA995X chips") Signed-off-by: Javier Carrasco <[email protected]> Link: https://lore.kernel.org/r/20240807-leds-pca995x-fix-fwnode-usage-v1-1-8057c84dc583@gmail.com Signed-off-by: Lee Jones <[email protected]>
1 parent 616dbed commit 82c5ada

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

drivers/leds/leds-pca995x.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,11 @@ static const struct regmap_config pca995x_regmap = {
120120
static int pca995x_probe(struct i2c_client *client)
121121
{
122122
struct fwnode_handle *led_fwnodes[PCA995X_MAX_OUTPUTS] = { 0 };
123-
struct fwnode_handle *child;
124123
struct device *dev = &client->dev;
125124
const struct pca995x_chipdef *chipdef;
126125
struct pca995x_chip *chip;
127126
struct pca995x_led *led;
128-
int i, reg, ret;
127+
int i, j, reg, ret;
129128

130129
chipdef = device_get_match_data(&client->dev);
131130

@@ -143,7 +142,7 @@ static int pca995x_probe(struct i2c_client *client)
143142

144143
i2c_set_clientdata(client, chip);
145144

146-
device_for_each_child_node(dev, child) {
145+
device_for_each_child_node_scoped(dev, child) {
147146
ret = fwnode_property_read_u32(child, "reg", &reg);
148147
if (ret)
149148
return ret;
@@ -152,7 +151,7 @@ static int pca995x_probe(struct i2c_client *client)
152151
return -EINVAL;
153152

154153
led = &chip->leds[reg];
155-
led_fwnodes[reg] = child;
154+
led_fwnodes[reg] = fwnode_handle_get(child);
156155
led->chip = chip;
157156
led->led_no = reg;
158157
led->ldev.brightness_set_blocking = pca995x_brightness_set;
@@ -171,7 +170,8 @@ static int pca995x_probe(struct i2c_client *client)
171170
&chip->leds[i].ldev,
172171
&init_data);
173172
if (ret < 0) {
174-
fwnode_handle_put(child);
173+
for (j = i; j < PCA995X_MAX_OUTPUTS; j++)
174+
fwnode_handle_put(led_fwnodes[j]);
175175
return dev_err_probe(dev, ret,
176176
"Could not register LED %s\n",
177177
chip->leds[i].ldev.name);

0 commit comments

Comments
 (0)