From: Kai-Heng Feng <kai.heng.feng@canonical.com>
To: ktsai@capellamicro.com, jic23@kernel.org, lars@metafoo.de
Cc: hdegoede@redhat.com, Kai-Heng Feng <kai.heng.feng@canonical.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] iio: light: cm32181: Unregister second I2C client if present
Date: Wed, 8 Feb 2023 15:21:41 +0800 [thread overview]
Message-ID: <20230208072141.1103738-1-kai.heng.feng@canonical.com> (raw)
If a second client that talks to the actual I2C address was created in
probe(), there should be a corresponding cleanup in remove() to avoid
leakage.
So if the "client" is not the same one used by I2C core, unregister it
accordingly.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2152281
Fixes: c1e62062ff54 ("iio: light: cm32181: Handle CM3218 ACPI devices with 2 I2C resources")
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
v2:
- Use devm_add_action_or_reset() instead of remove() callback to avoid
race.
drivers/iio/light/cm32181.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/drivers/iio/light/cm32181.c b/drivers/iio/light/cm32181.c
index b1674a5bfa368..a3e5f56101c9f 100644
--- a/drivers/iio/light/cm32181.c
+++ b/drivers/iio/light/cm32181.c
@@ -429,6 +429,16 @@ static const struct iio_info cm32181_info = {
.attrs = &cm32181_attribute_group,
};
+static void cm32181_disable(void *data)
+{
+ struct i2c_client *client = data;
+ struct cm32181_chip *cm32181 = iio_priv(i2c_get_clientdata(client));
+
+ /* Unregister the dummy client */
+ if (cm32181->client != client)
+ i2c_unregister_device(cm32181->client);
+}
+
static int cm32181_probe(struct i2c_client *client)
{
struct device *dev = &client->dev;
@@ -479,6 +489,12 @@ static int cm32181_probe(struct i2c_client *client)
return ret;
}
+ ret = devm_add_action_or_reset(dev, cm32181_disable, client);
+ if (ret) {
+ dev_err(dev, "%s: add devres action failed\n", __func__);
+ return ret;
+ }
+
ret = devm_iio_device_register(dev, indio_dev);
if (ret) {
dev_err(dev, "%s: regist device failed\n", __func__);
--
2.34.1
next reply other threads:[~2023-02-08 7:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-08 7:21 Kai-Heng Feng [this message]
2023-02-13 11:17 ` Hans de Goede
2023-02-22 13:50 ` Kai-Heng Feng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230208072141.1103738-1-kai.heng.feng@canonical.com \
--to=kai.heng.feng@canonical.com \
--cc=hdegoede@redhat.com \
--cc=jic23@kernel.org \
--cc=ktsai@capellamicro.com \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®