[PATCH] hwmon: (w83791d) remove fan/pwm 4-5 sysfs group on remove

Guangshuo Li posted 1 patch 1 week, 4 days ago
drivers/hwmon/w83791d.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] hwmon: (w83791d) remove fan/pwm 4-5 sysfs group on remove
Posted by Guangshuo Li 1 week, 4 days ago
When the fan/pwm 4-5 pins are not used as GPIO, w83791d_probe()
creates the w83791d_group_fanpwm45 sysfs group on the I2C client
device.

The probe error path removes this group when a later initialization
step fails, but the normal remove path only removes w83791d_group.
As a result, the optional fan/pwm 4-5 sysfs files can remain after the
driver is unbound.

The callbacks associated with these files access the driver data,
which is devm allocated and released after driver unbind. Leaving the
sysfs files behind can therefore result in accesses to stale driver
data.

Remove w83791d_group_fanpwm45 during normal teardown as well.

This issue was found by manual code inspection.

Fixes: 6e1ecd9b8f13 ("hwmon: (w83791d) fan 4/5 pins can also be used for gpio")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 drivers/hwmon/w83791d.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c
index 4a777430af5c..4b07a25ae59e 100644
--- a/drivers/hwmon/w83791d.c
+++ b/drivers/hwmon/w83791d.c
@@ -1415,6 +1415,7 @@ static void w83791d_remove(struct i2c_client *client)
 	struct w83791d_data *data = i2c_get_clientdata(client);
 
 	hwmon_device_unregister(data->hwmon_dev);
+	sysfs_remove_group(&client->dev.kobj, &w83791d_group_fanpwm45);
 	sysfs_remove_group(&client->dev.kobj, &w83791d_group);
 }
 
-- 
2.43.0
Re: [PATCH] hwmon: (w83791d) remove fan/pwm 4-5 sysfs group on remove
Posted by Guenter Roeck 1 week, 3 days ago
On Mon, Sep 14, 2026 at 02:28:09PM +0800, Guangshuo Li wrote:
> When the fan/pwm 4-5 pins are not used as GPIO, w83791d_probe()
> creates the w83791d_group_fanpwm45 sysfs group on the I2C client
> device.
> 
> The probe error path removes this group when a later initialization
> step fails, but the normal remove path only removes w83791d_group.
> As a result, the optional fan/pwm 4-5 sysfs files can remain after the
> driver is unbound.
> 
> The callbacks associated with these files access the driver data,
> which is devm allocated and released after driver unbind. Leaving the
> sysfs files behind can therefore result in accesses to stale driver
> data.
> 
> Remove w83791d_group_fanpwm45 during normal teardown as well.
> 
> This issue was found by manual code inspection.
> 
> Fixes: 6e1ecd9b8f13 ("hwmon: (w83791d) fan 4/5 pins can also be used for gpio")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>

Applied.

Thanks,
Guenter