iio: light: cm32181: Unregister second I2C client if present
Subsystems (2)
PATCH v4 1/1 iio: light: cm32181: Unregister second I2C client if present
If a second dummy client that talks to the actual I2C address was created in probe(), there should be a proper cleanup on driver and device removal to avoid leakage.
So unregister the dummy client via another callback.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2152281
---
v4:
- Remove logging kmalloc failures.
v3:
- Use devm_add_action_or_reset() in a correct place.
- Wording.
v2:
- Use devm_add_action_or_reset() instead of remove() callback to avoid race.
drivers/iio/light/cm32181.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/iio/light/cm32181.c +12 -0
@@ -429,6 +429,14 @@ static const struct iio_info cm32181_info = { .attrs = &cm32181_attribute_group, }; +static void cm32181_unregister_dummy_client (void *data) +{ +struct i2c_client *client = data; + +/* Unregister the dummy client */ +i2c_unregister_device (client); +} +static int cm32181_probe (struct i2c_client *client) {struct device *dev = &client->dev;
@@ -460,6 +468,10 @@ static int cm32181_probe(struct i2c_client *client) client =i2c_acpi_new_device (dev,1 , &board_info);if (IS_ERR (client))return PTR_ERR (client); + + ret =devm_add_action_or_reset (dev, cm32181_unregister_dummy_client, client); +if (ret) +return ret; } cm32181 =iio_priv (indio_dev);
Signature · 1 line
2.34.1
Hi,
Quoted 11 lines · Kai-Heng Feng
If a second dummy client that talks to the actual I2C address was created in
probe(), there should be a proper cleanup on driver and device removal to avoid leakage.So unregister the dummy client via another callback.
Reviewed-by Hans de Goede <[email protected]>Suggested-by Hans de Goede <[email protected]>Fixes c1e62062ff54 ("iio: light: cm32181: Handle CM3218 ACPI devices with 2 I2C resources")Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2152281
Signed-off-by Kai-Heng Feng <[email protected]>
Thanks this patch looks good to me now, and you
already added my Reviewed-by, so from my POV this
is ready for merging now.
Regards,
Hans
Quoted 45 lines
---
v4:
- Remove logging kmalloc failures.v3:
- Usedevm_add_action_or_reset()in a correct place.
- Wording.v2:
- Usedevm_add_action_or_reset()instead ofremove()callback to avoid race.drivers/iio/light/cm32181.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/iio/light/cm32181.c +12
-0@@ -429,6 +429,14 @@ static const struct iio_info cm32181_info = { .attrs = &cm32181_attribute_group, }; +static void cm32181_unregister_dummy_client (void *data) +{ +struct i2c_client *client = data; + +/* Unregister the dummy client */ +i2c_unregister_device (client); +} +static int cm32181_probe (struct i2c_client *client) {struct device *dev = &client->dev;@@ -460,6 +468,10 @@ static int cm32181_probe(struct i2c_client *client) client =i2c_acpi_new_device (dev,1 , &board_info);if (IS_ERR (client))return PTR_ERR (client); + + ret =devm_add_action_or_reset (dev, cm32181_unregister_dummy_client, client); +if (ret) +return ret; } cm32181 =iio_priv (indio_dev);
Quoted 15 lines · On Thu, 23 Feb 2023 09:41:29 +0100 Hans de Goede <[email protected]> wrote:
Hi,
Quoted 11 lines · Kai-Heng Feng
If a second dummy client that talks to the actual I2C address was created in
probe(), there should be a proper cleanup on driver and device removal to avoid leakage.So unregister the dummy client via another callback.
Reviewed-by Hans de Goede <[email protected]>Suggested-by Hans de Goede <[email protected]>Fixes c1e62062ff54 ("iio: light: cm32181: Handle CM3218 ACPI devices with 2 I2C resources")Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2152281
Signed-off-by Kai-Heng Feng <[email protected]>
Quoted 4 lines
Thanks this patch looks good to me now, and you
already added my Reviewed-by, so from my POV this
is ready for merging now.
Applied to the fixes-togreg branch of iio.git and marked for stable inclusion.
Thanks,
Jonathan
Quoted 50 lines
Regards,
Hans
Quoted 45 lines
---
v4:
- Remove logging kmalloc failures.v3:
- Usedevm_add_action_or_reset()in a correct place.
- Wording.v2:
- Usedevm_add_action_or_reset()instead ofremove()callback to avoid race.drivers/iio/light/cm32181.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/iio/light/cm32181.c +12
-0@@ -429,6 +429,14 @@ static const struct iio_info cm32181_info = { .attrs = &cm32181_attribute_group, }; +static void cm32181_unregister_dummy_client (void *data) +{ +struct i2c_client *client = data; + +/* Unregister the dummy client */ +i2c_unregister_device (client); +} +static int cm32181_probe (struct i2c_client *client) {struct device *dev = &client->dev;@@ -460,6 +468,10 @@ static int cm32181_probe(struct i2c_client *client) client =i2c_acpi_new_device (dev,1 , &board_info);if (IS_ERR (client))return PTR_ERR (client); + + ret =devm_add_action_or_reset (dev, cm32181_unregister_dummy_client, client); +if (ret) +return ret; } cm32181 =iio_priv (indio_dev);