hwmon: chipcap2: disable device after hwmon teardown

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: 3af350929e ("hwmon: Add support for Amphenol ChipCap 2")
Cc: stable@vger.kernel.org
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Link: https://patch.msgid.link/20261014-chipcap2_locks-v3-6-27ebfc2c5b9e@gmail.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
Javier Carrasco 2026-10-14 19:34:05 +02:00 committed by Guenter Roeck
parent d2a66c515d
commit 4724ac5556

View File

@ -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);