Skip to content

Commit 099cc90

Browse files
khfengjic23
authored andcommitted
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. Reviewed-by: Hans de Goede <hdegoede@redhat.com> Suggested-by: Hans de Goede <hdegoede@redhat.com> Fixes: c1e6206 ("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 <kai.heng.feng@canonical.com> Link: https://lore.kernel.org/r/20230223020059.2013993-1-kai.heng.feng@canonical.com Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 03fada4 commit 099cc90

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

drivers/iio/light/cm32181.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,14 @@ static const struct iio_info cm32181_info = {
429429
.attrs = &cm32181_attribute_group,
430430
};
431431

432+
static void cm32181_unregister_dummy_client(void *data)
433+
{
434+
struct i2c_client *client = data;
435+
436+
/* Unregister the dummy client */
437+
i2c_unregister_device(client);
438+
}
439+
432440
static int cm32181_probe(struct i2c_client *client)
433441
{
434442
struct device *dev = &client->dev;
@@ -460,6 +468,10 @@ static int cm32181_probe(struct i2c_client *client)
460468
client = i2c_acpi_new_device(dev, 1, &board_info);
461469
if (IS_ERR(client))
462470
return PTR_ERR(client);
471+
472+
ret = devm_add_action_or_reset(dev, cm32181_unregister_dummy_client, client);
473+
if (ret)
474+
return ret;
463475
}
464476

465477
cm32181 = iio_priv(indio_dev);

0 commit comments

Comments
 (0)