Skip to contentSkip to conversation

iio: light: veml6070: Fix resource leak in probe error path

PATCH Applied Felix Gu 2 participants 2 messages Mar 27 – Apr 12 IIO

lore
Share & tools
lore

Felix Gu

author
#0 lore raw

PATCH v2 1/1 iio: light: veml6070: Fix resource leak in probe error path

The driver calls i2c_new_dummy_device() to create a dummy device, then calls i2c_smbus_write_byte(). If i2c_smbus_write_byte() fails and returns, the cleanup via devm_add_action_or_reset() was never registered, so the dummy device leaks.

Switch to devm_i2c_new_dummy_device() which registers cleanup atomically with device creation, eliminating the error-path window.

Fixes 7501bff87c3e ("iio: light: veml6070: add action for i2c_unregister_device")

---
Changes in v2:
- Rewrite the commit message.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 drivers/iio/light/veml6070.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
drivers/iio/light/veml6070.c +2 -12
index 6d4483c85f30..416a9520713f 100644
@@ -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]>
maintainer Applied
#1 lore raw
Quoted 11 lines · On Fri, 27 Mar 2026 20:27:54 +0800 Felix Gu <[email protected]> wrote:

The driver calls i2c_new_dummy_device() to create a dummy device, then calls i2c_smbus_write_byte(). If i2c_smbus_write_byte() fails and returns, the cleanup via devm_add_action_or_reset() was never registered, so the dummy device leaks.

Switch to devm_i2c_new_dummy_device() which registers cleanup atomically with device creation, eliminating the error-path window.

Fixes 7501bff87c3e ("iio: light: veml6070: add action for i2c_unregister_device")

Applied to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

Jonathan