Linux LED subsystem development
 help / color / mirror / Atom feed
* [PATCH] leds: lp55xx: roll back engine sysfs group on failure
@ 2026-06-15  6:49 Pengpeng Hou
  2026-07-01 21:54 ` Lee Jones
  0 siblings, 1 reply; 2+ messages in thread
From: Pengpeng Hou @ 2026-06-15  6:49 UTC (permalink / raw)
  To: Lee Jones, Pavel Machek, linux-leds, linux-kernel; +Cc: pengpeng

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@iscas.ac.cn>
---
 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)


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-01 21:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-15  6:49 [PATCH] leds: lp55xx: roll back engine sysfs group on failure Pengpeng Hou
2026-07-01 21:54 ` Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox