Skip to contentSkip to conversation

leds: blinkm: Remove sysfs group on allocation failure

PATCH In review Myeonghun Pak 3 participants 5 messages Sep 15 – Sep 22

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 leds: blinkm: Remove sysfs group on allocation failure

register_multicolor() returns on allocation failure without removing the sysfs group created by blinkm_probe(). Remove it on this path, matching the helper's existing LED registration error cleanup.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes 56e8c56c9af0 ("leds: Add multicolor support to BlinkM LED driver")
Assisted-by LLM
---
 drivers/leds/leds-blinkm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/leds/leds-blinkm.c +3 -1
@@ -691,8 +691,10 @@ static int register_multicolor(struct i2c_client *client, struct blinkm_data *da
 
 	mc_led_info = devm_kcalloc(&client->dev, NUM_LEDS, sizeof(*mc_led_info),
 					GFP_KERNEL);
-	if (!mc_led_info)
+	if (!mc_led_info) {
+		sysfs_remove_group(&client->dev.kobj, &blinkm_group);
 		return -ENOMEM;
+	}
 
 	mc_led_info[RED].color_index = LED_COLOR_ID_RED;
 	mc_led_info[GREEN].color_index = LED_COLOR_ID_GREEN;
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines

register_multicolor() returns on allocation failure without removing the sysfs group created by blinkm_probe(). Remove it on this path, matching the helper's existing LED registration error cleanup.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Quoted 6 lines
Fixes 56e8c56c9af0 ("leds: Add multicolor support to BlinkM LED driver")
Assisted-by LLM

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#2 lore raw
In reply to Myeonghun Pak
Quoted 21 lines · Myeonghun Pak

register_multicolor() returns on allocation failure without removing the sysfs group created by blinkm_probe(). Remove it on this path, matching the helper's existing LED registration error cleanup.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes 56e8c56c9af0 ("leds: Add multicolor support to BlinkM LED driver")
Assisted-by LLM
---
 drivers/leds/leds-blinkm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

drivers/leds/leds-blinkm.c static int register_multicolor(struct i2c_client *client, struct blinkm_data *da · line 695

Quoted 6 lines
drivers/leds/leds-blinkm.c +2 -1
@@ -691,8 +691,10 @@ static int register_multicolor(struct i2c_client *client, struct blinkm_data *da
 
 	mc_led_info = devm_kcalloc(&client->dev, NUM_LEDS, sizeof(*mc_led_info),
 					GFP_KERNEL);
-	if (!mc_led_info)
+	if (!mc_led_info) {
+		sysfs_remove_group(&client->dev.kobj, &blinkm_group);

If 'blinkm_group' was created in blinkm_probe(), shouldn't it be cleaned up in the error path of 'blinkm_probe()' rather than here in the callee?

Quoted 5 lines
drivers/leds/leds-blinkm.c +1 -0
 		return -ENOMEM;
+	}
 
 	mc_led_info[RED].color_index = LED_COLOR_ID_RED;
 	mc_led_info[GREEN].color_index = LED_COLOR_ID_GREEN;
Signature · 1 line
Lee Jones
maintainer
#3 lore raw
Quoted 24 lines · Lee Jones
Quoted 22 lines · Myeonghun Pak

register_multicolor() returns on allocation failure without removing the sysfs group created by blinkm_probe(). Remove it on this path, matching the helper's existing LED registration error cleanup.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes 56e8c56c9af0 ("leds: Add multicolor support to BlinkM LED driver")
Assisted-by LLM
---
 drivers/leds/leds-blinkm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/leds/leds-blinkm.c +0 -0
@@ -691,8 +691,10 @@ static int register_multicolor(struct i2c_client *client, struct blinkm_data *da
 
Quoted 8 lines

drivers/leds/leds-blinkm.c static int register_multicolor(struct i2c_client *client, struct blinkm_data *da · line 695

Quoted 5 lines
drivers/leds/leds-blinkm.c +2 -1
 	mc_led_info = devm_kcalloc(&client->dev, NUM_LEDS, sizeof(*mc_led_info),
 					GFP_KERNEL);
-	if (!mc_led_info)
+	if (!mc_led_info) {
+		sysfs_remove_group(&client->dev.kobj, &blinkm_group);

If 'blinkm_group' was created in blinkm_probe(), shouldn't it be cleaned up in the error path of 'blinkm_probe()' rather than here in the callee?

Same with register_separate_colors() failure, no?

Quoted 9 lines
Quoted 6 lines
drivers/leds/leds-blinkm.c +1 -0
 		return -ENOMEM;
+	}
 
 	mc_led_info[RED].color_index = LED_COLOR_ID_RED;
 	mc_led_info[GREEN].color_index = LED_COLOR_ID_GREEN;
Signature · 1 line
Lee Jones
Signature · 1 line
Lee Jones
maintainer
#4 lore raw
Quoted 35 lines · Lee Jones
Quoted 24 lines · Lee Jones
Quoted 22 lines · Myeonghun Pak

register_multicolor() returns on allocation failure without removing the sysfs group created by blinkm_probe(). Remove it on this path, matching the helper's existing LED registration error cleanup.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes 56e8c56c9af0 ("leds: Add multicolor support to BlinkM LED driver")
Assisted-by LLM
---
 drivers/leds/leds-blinkm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/leds/leds-blinkm.c +0 -0
@@ -691,8 +691,10 @@ static int register_multicolor(struct i2c_client *client, struct blinkm_data *da
 
Quoted 8 lines

drivers/leds/leds-blinkm.c static int register_multicolor(struct i2c_client *client, struct blinkm_data *da · line 695

Quoted 5 lines
drivers/leds/leds-blinkm.c +2 -1
 	mc_led_info = devm_kcalloc(&client->dev, NUM_LEDS, sizeof(*mc_led_info),
 					GFP_KERNEL);
-	if (!mc_led_info)
+	if (!mc_led_info) {
+		sysfs_remove_group(&client->dev.kobj, &blinkm_group);

If 'blinkm_group' was created in blinkm_probe(), shouldn't it be cleaned up in the error path of 'blinkm_probe()' rather than here in the callee?

Quoted 1 line

Same with register_separate_colors() failure, no?

What about:

drivers/leds/leds-blinkm.c +7 -9
index ee1589015826..7932095780aa 100644
@@ -749,19 +749,17 @@ static int blinkm_probe(struct i2c_client *client)
                return err;
        }
 
-       if (!IS_ENABLED(CONFIG_LEDS_BLINKM_MULTICOLOR)) {
+       if (!IS_ENABLED(CONFIG_LEDS_BLINKM_MULTICOLOR))
                err = register_separate_colors(client, data);
-               if (err < 0)
-                       return err;
-       } else {
+        else
                err = register_multicolor(client, data);
-               if (err < 0)
-                       return err;
-       }
 
-       blinkm_init_hw(client);
+       if (err < 0)
+               sysfs_remove_group(&client->dev.kobj, &blinkm_group);
+       else
+               blinkm_init_hw(client);
 
-       return 0;
+       return err;
 }
 

This is completely untested.

Signature · 1 line
Lee Jones