[PATCH v3 06/11] hwmon: chipcap2: disable device after hwmon teardown

From: Javier Carrasco

Date: Wed Oct 14 2026 - 13:36:59 EST


cc2_remove() disables the device while the device-managed hwmon device is
still registered. A concurrent sysfs callback can then enable the device
after it has been disabled during removal.

Register a device-managed disable action before registering the hwmon
device, so devres unregisters the hwmon device before disabling the
physical device.

Fixes: 3af350929e75 ("hwmon: Add support for Amphenol ChipCap 2")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@xxxxxxxxx>
---
drivers/hwmon/chipcap2.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/hwmon/chipcap2.c b/drivers/hwmon/chipcap2.c
index 21dc6db27c40..654f6420da7a 100644
--- a/drivers/hwmon/chipcap2.c
+++ b/drivers/hwmon/chipcap2.c
@@ -152,6 +152,11 @@ static void cc2_disable(struct cc2_data *data)
}
}

+static void cc2_disable_action(void *data)
+{
+ cc2_disable(data);
+}
+
static int cc2_cmd_response_diagnostic(struct device *dev, u8 status)
{
int resp;
@@ -744,6 +749,10 @@ static int cc2_probe(struct i2c_client *client)
if (ret)
return dev_err_probe(dev, ret, "Failed to get IRQs\n");

+ ret = devm_add_action_or_reset(dev, cc2_disable_action, data);
+ if (ret)
+ return ret;
+
ret = cc2_request_data_ready(data, dev);
if (ret)
return dev_err_probe(dev, ret, "Failed to request ready irq\n");
@@ -762,13 +771,6 @@ static int cc2_probe(struct i2c_client *client)
return 0;
}

-static void cc2_remove(struct i2c_client *client)
-{
- struct cc2_data *data = i2c_get_clientdata(client);
-
- cc2_disable(data);
-}
-
static const struct i2c_device_id cc2_id[] = {
{ .name = "cc2d23" },
{ .name = "cc2d23s" },
@@ -801,7 +803,6 @@ static struct i2c_driver cc2_driver = {
.of_match_table = cc2_of_match,
},
.probe = cc2_probe,
- .remove = cc2_remove,
.id_table = cc2_id,
};
module_i2c_driver(cc2_driver);

--
2.43.0