[PATCH] leds: lp55xx: roll back engine sysfs group on failure
From: Pengpeng Hou
Date: Mon Jun 15 2026 - 02:51:10 EST
lp55xx_register_sysfs() creates the common engine sysfs group before
creating the optional chip-specific sysfs group.
If the chip-specific group creation fails, the function returns the
error directly and leaves the engine group published even though probe
fails and the chip state will be torn down.
Remove the engine group when the later chip-specific group creation
fails.
Signed-off-by: Pengpeng Hou <pengpeng@xxxxxxxxxxx>
---
drivers/leds/leds-lp55xx-common.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c
index ea131177de96..501762b02667 100644
--- a/drivers/leds/leds-lp55xx-common.c
+++ b/drivers/leds/leds-lp55xx-common.c
@@ -1090,6 +1090,7 @@ static int lp55xx_register_sysfs(struct lp55xx_chip *chip)
{
struct device *dev = &chip->cl->dev;
const struct lp55xx_device_config *cfg = chip->cfg;
+ bool engine_group_created = false;
int ret;
if (!cfg->run_engine || !cfg->firmware_cb)
@@ -1098,10 +1099,17 @@ static int lp55xx_register_sysfs(struct lp55xx_chip *chip)
ret = sysfs_create_group(&dev->kobj, &lp55xx_engine_attr_group);
if (ret)
return ret;
+ engine_group_created = true;
dev_specific_attrs:
- return cfg->dev_attr_group ?
- sysfs_create_group(&dev->kobj, cfg->dev_attr_group) : 0;
+ if (!cfg->dev_attr_group)
+ return 0;
+
+ ret = sysfs_create_group(&dev->kobj, cfg->dev_attr_group);
+ if (ret && engine_group_created)
+ sysfs_remove_group(&dev->kobj, &lp55xx_engine_attr_group);
+
+ return ret;
}
static void lp55xx_unregister_sysfs(struct lp55xx_chip *chip)
--
2.50.1 (Apple Git-155)