[PATCH] misc: ad525x_dpot: fix sysfs cleanup paths

From: Pengpeng Hou

Date: Mon Jun 15 2026 - 02:56:48 EST


ad_dpot_probe() creates per-RDAC sysfs files and then, for devices with
increment/decrement commands, creates the command sysfs group.

If creating the command group fails, the probe error path frees the
driver data without removing the per-RDAC files created earlier.
Conversely, ad_dpot_remove() removes the per-RDAC files but never
removes the command group.

Route command-group creation failure through the existing per-RDAC
cleanup path and remove the command group during normal teardown.

Signed-off-by: Pengpeng Hou <pengpeng@xxxxxxxxxxx>
---
drivers/misc/ad525x_dpot.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/ad525x_dpot.c b/drivers/misc/ad525x_dpot.c
index 57bead9fba1b..866fdddd8b0e 100644
--- a/drivers/misc/ad525x_dpot.c
+++ b/drivers/misc/ad525x_dpot.c
@@ -719,7 +719,7 @@ int ad_dpot_probe(struct device *dev,

if (err) {
dev_err(dev, "failed to register sysfs hooks\n");
- goto exit_free;
+ goto exit_remove_files;
}

dev_info(dev, "%s %d-Position Digital Potentiometer registered\n",
@@ -751,6 +751,9 @@ void ad_dpot_remove(struct device *dev)
if (data->wipers & (1 << i))
ad_dpot_remove_files(dev, data->feat, i);

+ if (data->feat & F_CMD_INC)
+ sysfs_remove_group(&dev->kobj, &ad525x_group_commands);
+
kfree(data);
}
EXPORT_SYMBOL(ad_dpot_remove);
--
2.50.1 (Apple Git-155)