From: Johan Hovold <johan@kernel.org>
To: Andi Shyti <andi.shyti@kernel.org>
Cc: Wolfram Sang <wsa+renesas@sang-engineering.com>,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
Johan Hovold <johan@kernel.org>
Subject: [PATCH 2/3] i2c: dev: drop unnecessary sysfs device lookup
Date: Thu, 27 Aug 2026 11:08:03 +0200 [thread overview]
Message-ID: <20260827090804.638565-3-johan@kernel.org> (raw)
In-Reply-To: <20260827090804.638565-1-johan@kernel.org>
The sysfs lifetime rules guarantees that the i2c-dev class device is
still valid while its attribute callbacks are executing so drop the
unnecessary reverse lookup.
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/i2c/i2c-dev.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index 05616249f61b..319bc46cc207 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -47,6 +47,7 @@ struct i2c_dev {
struct device dev;
struct cdev cdev;
};
+#define to_i2c_dev(d) container_of((d), struct i2c_dev, dev)
struct i2c_dev_data {
struct i2c_dev *i2c_dev;
@@ -111,10 +112,8 @@ static void put_i2c_dev(struct i2c_dev *i2c_dev, bool del_cdev)
static ssize_t name_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct i2c_dev *i2c_dev = i2c_dev_get_by_minor(MINOR(dev->devt));
+ struct i2c_dev *i2c_dev = to_i2c_dev(dev);
- if (!i2c_dev)
- return -ENODEV;
return sysfs_emit(buf, "%s\n", i2c_dev->adap->name);
}
static DEVICE_ATTR_RO(name);
@@ -704,9 +703,8 @@ static const struct class i2c_dev_class = {
static void i2cdev_dev_release(struct device *dev)
{
- struct i2c_dev *i2c_dev;
+ struct i2c_dev *i2c_dev = to_i2c_dev(dev);
- i2c_dev = container_of(dev, struct i2c_dev, dev);
kfree(i2c_dev);
}
--
2.54.0
next prev parent reply other threads:[~2026-08-27 9:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-27 9:08 [PATCH 0/3] i2c: dev: fix blocked adapter deregistration Johan Hovold
2026-08-27 9:08 ` [PATCH 1/3] " Johan Hovold
2026-08-27 9:43 ` Johan Hovold
2026-08-27 9:08 ` Johan Hovold [this message]
2026-08-27 9:08 ` [PATCH 3/3] i2c: dev: clean up registration Johan Hovold
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=20260827090804.638565-3-johan@kernel.org \
--to=johan@kernel.org \
--cc=andi.shyti@kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wsa+renesas@sang-engineering.com \
/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®