[PATCH] mfd: tps65911-comparator: fix sysfs file creation rollback

From: Pengpeng Hou

Date: Mon Jun 15 2026 - 02:51:11 EST


tps65911_comparator_probe() creates comp1_threshold and then
comp2_threshold sysfs files.

If creating comp1_threshold fails, the probe still tries to create
comp2_threshold and can return success if the second creation succeeds.
If creating comp2_threshold fails, the already-created comp1_threshold
file is left behind even though probe returns an error.

Return immediately on comp1_threshold creation failure and remove
comp1_threshold when comp2_threshold creation fails.

Signed-off-by: Pengpeng Hou <pengpeng@xxxxxxxxxxx>
---
drivers/mfd/tps65911-comparator.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/mfd/tps65911-comparator.c b/drivers/mfd/tps65911-comparator.c
index 7098712ea008..2e5211374aaf 100644
--- a/drivers/mfd/tps65911-comparator.c
+++ b/drivers/mfd/tps65911-comparator.c
@@ -130,12 +130,16 @@ static int tps65911_comparator_probe(struct platform_device *pdev)

/* Create sysfs entry */
ret = device_create_file(&pdev->dev, &dev_attr_comp1_threshold);
- if (ret < 0)
+ if (ret < 0) {
dev_err(&pdev->dev, "failed to add COMP1 sysfs file\n");
+ return ret;
+ }

ret = device_create_file(&pdev->dev, &dev_attr_comp2_threshold);
- if (ret < 0)
+ if (ret < 0) {
dev_err(&pdev->dev, "failed to add COMP2 sysfs file\n");
+ device_remove_file(&pdev->dev, &dev_attr_comp1_threshold);
+ }

return ret;
}
--
2.50.1 (Apple Git-155)