leds: blinkm: Remove sysfs group on allocation failure
Subsystems (3)
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.
--- 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 ;
[email protected]
AI reviewSashiko 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 byblinkm_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 LLMCo-developed-by Ijae Kim <[email protected]>Signed-off-by Ijae Kim <[email protected]>Signed-off-by Myeonghun Pak <[email protected]>
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
Lee Jones
maintainerQuoted 21 lines · Myeonghun Pak
register_multicolor()returns on allocation failure without removing the sysfs group created byblinkm_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 LLMCo-developed-by Ijae Kim <[email protected]>Signed-off-by Ijae Kim <[email protected]>Signed-off-by Myeonghun Pak <[email protected]>--- 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
-0return -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
Lee Jones
maintainerQuoted 24 lines · Lee Jones
Quoted 22 lines · Myeonghun Pak
register_multicolor()returns on allocation failure without removing the sysfs group created byblinkm_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 LLMCo-developed-by Ijae Kim <[email protected]>Signed-off-by Ijae Kim <[email protected]>Signed-off-by Myeonghun Pak <[email protected]>--- 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
-1mc_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 inblinkm_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
-0return -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
Lee Jones
maintainerQuoted 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 byblinkm_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 LLMCo-developed-by Ijae Kim <[email protected]>Signed-off-by Ijae Kim <[email protected]>Signed-off-by Myeonghun Pak <[email protected]>--- 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 *daQuoted 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
-1mc_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 inblinkm_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
@@ -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