From: Adrian Hunter <adrian.hunter@intel.com>
To: alexandre.belloni@bootlin.com
Cc: Frank.Li@nxp.com, Adrian Ng Ho Yin <adrian.ho.yin.ng@altera.com>,
linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/3] i3c: master: Update dev_nack_retry_count under maintenance lock
Date: Tue, 16 Jun 2026 14:37:50 +0300 [thread overview]
Message-ID: <20260616113752.196140-2-adrian.hunter@intel.com> (raw)
In-Reply-To: <20260616113752.196140-1-adrian.hunter@intel.com>
Protect master->dev_nack_retry_count against concurrent sysfs updates
by updating it while holding the bus maintenance lock.
Consequently, combine adjacent return statements into one.
For consistency, read dev_nack_retry_count while holding the bus normaluse
lock.
Fixes: b58f47eb39268 ("i3c: add sysfs entry and attribute for Device NACK Retry count")
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
drivers/i3c/master.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 367e0d6d4a64..66cf5d3bd987 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -744,7 +744,14 @@ static DEVICE_ATTR_RW(hotjoin);
static ssize_t dev_nack_retry_count_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- return sysfs_emit(buf, "%u\n", dev_to_i3cmaster(dev)->dev_nack_retry_count);
+ struct i3c_bus *i3cbus = dev_to_i3cbus(dev);
+ ssize_t ret;
+
+ i3c_bus_normaluse_lock(i3cbus);
+ ret = sysfs_emit(buf, "%u\n", dev_to_i3cmaster(dev)->dev_nack_retry_count);
+ i3c_bus_normaluse_unlock(i3cbus);
+
+ return ret;
}
static ssize_t dev_nack_retry_count_store(struct device *dev,
@@ -762,14 +769,11 @@ static ssize_t dev_nack_retry_count_store(struct device *dev,
i3c_bus_maintenance_lock(i3cbus);
ret = master->ops->set_dev_nack_retry(master, val);
+ if (!ret)
+ master->dev_nack_retry_count = val;
i3c_bus_maintenance_unlock(i3cbus);
- if (ret)
- return ret;
-
- master->dev_nack_retry_count = val;
-
- return count;
+ return ret ?: count;
}
static DEVICE_ATTR_RW(dev_nack_retry_count);
--
2.51.0
--
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c
WARNING: multiple messages have this Message-ID (diff)
From: Adrian Hunter <adrian.hunter@intel.com>
To: alexandre.belloni@bootlin.com
Cc: Frank.Li@nxp.com, Adrian Ng Ho Yin <adrian.ho.yin.ng@altera.com>,
linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/3] i3c: master: Update dev_nack_retry_count under maintenance lock
Date: Tue, 16 Jun 2026 14:37:50 +0300 [thread overview]
Message-ID: <20260616113752.196140-2-adrian.hunter@intel.com> (raw)
In-Reply-To: <20260616113752.196140-1-adrian.hunter@intel.com>
Protect master->dev_nack_retry_count against concurrent sysfs updates
by updating it while holding the bus maintenance lock.
Consequently, combine adjacent return statements into one.
For consistency, read dev_nack_retry_count while holding the bus normaluse
lock.
Fixes: b58f47eb39268 ("i3c: add sysfs entry and attribute for Device NACK Retry count")
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
drivers/i3c/master.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 367e0d6d4a64..66cf5d3bd987 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -744,7 +744,14 @@ static DEVICE_ATTR_RW(hotjoin);
static ssize_t dev_nack_retry_count_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- return sysfs_emit(buf, "%u\n", dev_to_i3cmaster(dev)->dev_nack_retry_count);
+ struct i3c_bus *i3cbus = dev_to_i3cbus(dev);
+ ssize_t ret;
+
+ i3c_bus_normaluse_lock(i3cbus);
+ ret = sysfs_emit(buf, "%u\n", dev_to_i3cmaster(dev)->dev_nack_retry_count);
+ i3c_bus_normaluse_unlock(i3cbus);
+
+ return ret;
}
static ssize_t dev_nack_retry_count_store(struct device *dev,
@@ -762,14 +769,11 @@ static ssize_t dev_nack_retry_count_store(struct device *dev,
i3c_bus_maintenance_lock(i3cbus);
ret = master->ops->set_dev_nack_retry(master, val);
+ if (!ret)
+ master->dev_nack_retry_count = val;
i3c_bus_maintenance_unlock(i3cbus);
- if (ret)
- return ret;
-
- master->dev_nack_retry_count = val;
-
- return count;
+ return ret ?: count;
}
static DEVICE_ATTR_RW(dev_nack_retry_count);
--
2.51.0
next prev parent reply other threads:[~2026-06-16 11:38 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-16 11:37 [PATCH 0/3] i3c: master: Small fixes for dev_nack_retry_count Adrian Hunter
2026-06-16 11:37 ` Adrian Hunter
2026-06-16 11:37 ` Adrian Hunter [this message]
2026-06-16 11:37 ` [PATCH 1/3] i3c: master: Update dev_nack_retry_count under maintenance lock Adrian Hunter
2026-06-16 11:51 ` sashiko-bot
2026-06-16 13:30 ` Adrian Hunter
2026-06-16 16:55 ` Frank Li
2026-06-16 16:55 ` Frank Li
2026-06-16 11:37 ` [PATCH 2/3] i3c: master: Add missing runtime PM get in dev_nack_retry_count_store() Adrian Hunter
2026-06-16 11:37 ` Adrian Hunter
2026-06-16 11:51 ` sashiko-bot
2026-06-16 13:46 ` Adrian Hunter
2026-06-16 16:56 ` Frank Li
2026-06-16 16:56 ` Frank Li
2026-06-16 11:37 ` [PATCH 3/3] i3c: master: Use unsigned int for dev_nack_retry_count consistently Adrian Hunter
2026-06-16 11:37 ` Adrian Hunter
2026-06-16 16:58 ` Frank Li
2026-06-16 16:58 ` Frank Li
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=20260616113752.196140-2-adrian.hunter@intel.com \
--to=adrian.hunter@intel.com \
--cc=Frank.Li@nxp.com \
--cc=adrian.ho.yin.ng@altera.com \
--cc=alexandre.belloni@bootlin.com \
--cc=linux-i3c@lists.infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.