iio: light: veml6070: Fix resource leak in probe error path
PATCH 1/1 iio: light: veml6070: Fix resource leak in probe error path
The original code registered the i2c dummy device cleanup via devm_add_action_or_reset() after i2c_new_dummy_device(). If probe failed between these two calls, the dummy device would leak.
Use devm_i2c_new_dummy_device() which registers cleanup atomically with device creation, eliminating the error-path window.
--- drivers/iio/light/veml6070.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
drivers/iio/light/veml6070.c +2 -12
@@ -247,13 +247,6 @@ static const struct iio_info veml6070_info = { .write_raw = veml6070_write_raw, }; -static void veml6070_i2c_unreg (void *p) -{ -struct veml6070_data *data = p; - -i2c_unregister_device (data->client2); -} -static int veml6070_probe (struct i2c_client *client) {struct veml6070_data *data;
@@ -283,7 +276,8 @@ static int veml6070_probe(struct i2c_client *client)if (ret <0 )return ret; - data->client2 =i2c_new_dummy_device (client->adapter,VEML6070_ADDR_DATA_LSB ); + data->client2 =devm_i2c_new_dummy_device (&client->dev, client->adapter, +VEML6070_ADDR_DATA_LSB );if (IS_ERR (data->client2))return dev_err_probe (&client->dev,PTR_ERR (data->client2),"i2c device for second chip address failed\n" );
@@ -294,10 +288,6 @@ static int veml6070_probe(struct i2c_client *client)if (ret <0 )return ret; - ret =devm_add_action_or_reset (&client->dev, veml6070_i2c_unreg, data); -if (ret <0 ) -return ret; -return devm_iio_device_register (&client->dev, indio_dev); }
---
base-commit: 66ba480978ce390e631e870b740a3406e3eb6b01
change-id: 20260326-veml6070-1489798087df
Best regards,
Signature · 1 line
Felix Gu <[email protected]>
Quoted 3 lines · Felix Gu
The original code registered the i2c dummy device cleanup via
devm_add_action_or_reset()afteri2c_new_dummy_device(). If probe failed between these two calls, the dummy device would leak.
I see what you meant by reading the code, but the above is simply wrong.
The
ret = i2c_new_dummy_device(); if (ret) return ret; // "probe failed between these two calls" ret = devm_add_action_or_reset();
Please, rephrase.
Quoted 2 lines
Use
devm_i2c_new_dummy_device()which registers cleanup atomically with device creation, eliminating the error-path window.
With the fixed commit message
Signature · 2 lines
With Best Regards, Andy Shevchenko