* [PATCH 0/3] i3c: master: Small fixes for dev_nack_retry_count
@ 2026-06-16 11:37 Adrian Hunter
2026-06-16 11:37 ` [PATCH 1/3] i3c: master: Update dev_nack_retry_count under maintenance lock Adrian Hunter
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Adrian Hunter @ 2026-06-16 11:37 UTC (permalink / raw)
To: alexandre.belloni; +Cc: Frank.Li, Adrian Ng Ho Yin, linux-i3c, linux-kernel
Hi
Here are some small fixes for dev_nack_retry_count.
Adrian Hunter (3):
i3c: master: Update dev_nack_retry_count under maintenance lock
i3c: master: Add missing runtime PM get in dev_nack_retry_count_store()
i3c: master: Use unsigned int for dev_nack_retry_count consistently
drivers/i3c/master.c | 26 ++++++++++++++++++--------
drivers/i3c/master/dw-i3c-master.c | 4 ++--
include/linux/i3c/master.h | 2 +-
3 files changed, 21 insertions(+), 11 deletions(-)
Regards
Adrian
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/3] i3c: master: Update dev_nack_retry_count under maintenance lock
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 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 ` [PATCH 3/3] i3c: master: Use unsigned int for dev_nack_retry_count consistently Adrian Hunter
2 siblings, 1 reply; 7+ messages in thread
From: Adrian Hunter @ 2026-06-16 11:37 UTC (permalink / raw)
To: alexandre.belloni; +Cc: Frank.Li, Adrian Ng Ho Yin, linux-i3c, linux-kernel
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3] i3c: master: Add missing runtime PM get in dev_nack_retry_count_store()
2026-06-16 11:37 [PATCH 0/3] i3c: master: Small fixes for dev_nack_retry_count Adrian Hunter
2026-06-16 11:37 ` [PATCH 1/3] i3c: master: Update dev_nack_retry_count under maintenance lock Adrian Hunter
@ 2026-06-16 11:37 ` Adrian Hunter
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
2 siblings, 1 reply; 7+ messages in thread
From: Adrian Hunter @ 2026-06-16 11:37 UTC (permalink / raw)
To: alexandre.belloni; +Cc: Frank.Li, Adrian Ng Ho Yin, linux-i3c, linux-kernel
Ensure the device is runtime resumed while updating the retry
configuration to avoid accessing the controller while suspended.
Call i3c_master_rpm_get() before accessing the controller in
dev_nack_retry_count_store() and release it with
i3c_master_rpm_put() afterwards.
Fixes: 990c149c61ee4 ("i3c: master: Introduce optional Runtime PM support")
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
drivers/i3c/master.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 66cf5d3bd987..903ac01ab413 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -767,12 +767,18 @@ static ssize_t dev_nack_retry_count_store(struct device *dev,
if (ret)
return ret;
+ ret = i3c_master_rpm_get(master);
+ if (ret)
+ return ret;
+
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);
+ i3c_master_rpm_put(master);
+
return ret ?: count;
}
--
2.51.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/3] i3c: master: Use unsigned int for dev_nack_retry_count consistently
2026-06-16 11:37 [PATCH 0/3] i3c: master: Small fixes for dev_nack_retry_count Adrian Hunter
2026-06-16 11:37 ` [PATCH 1/3] i3c: master: Update dev_nack_retry_count under maintenance lock Adrian Hunter
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 16:58 ` Frank Li
2 siblings, 1 reply; 7+ messages in thread
From: Adrian Hunter @ 2026-06-16 11:37 UTC (permalink / raw)
To: alexandre.belloni; +Cc: Frank.Li, Adrian Ng Ho Yin, linux-i3c, linux-kernel
Use unsigned int for dev_nack_retry_count across the core and
controller drivers to match the type of master->dev_nack_retry_count.
Update the sysfs store path to use kstrtouint() and adjust the
->set_dev_nack_retry() callback prototype and callers accordingly.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
drivers/i3c/master.c | 4 ++--
drivers/i3c/master/dw-i3c-master.c | 4 ++--
include/linux/i3c/master.h | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 903ac01ab413..58d20624ed05 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -760,10 +760,10 @@ static ssize_t dev_nack_retry_count_store(struct device *dev,
{
struct i3c_bus *i3cbus = dev_to_i3cbus(dev);
struct i3c_master_controller *master = dev_to_i3cmaster(dev);
- unsigned long val;
+ unsigned int val;
int ret;
- ret = kstrtoul(buf, 0, &val);
+ ret = kstrtouint(buf, 0, &val);
if (ret)
return ret;
diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
index c7030d0cd8a6..e4f6d6f29ed5 100644
--- a/drivers/i3c/master/dw-i3c-master.c
+++ b/drivers/i3c/master/dw-i3c-master.c
@@ -1481,7 +1481,7 @@ static irqreturn_t dw_i3c_master_irq_handler(int irq, void *dev_id)
}
static int dw_i3c_master_set_dev_nack_retry(struct i3c_master_controller *m,
- unsigned long dev_nack_retry_cnt)
+ unsigned int dev_nack_retry_cnt)
{
struct dw_i3c_master *master = to_dw_i3c_master(m);
u32 reg;
@@ -1489,7 +1489,7 @@ static int dw_i3c_master_set_dev_nack_retry(struct i3c_master_controller *m,
if (dev_nack_retry_cnt > DW_I3C_DEV_NACK_RETRY_CNT_MAX) {
dev_err(&master->base.dev,
- "Value %ld exceeds maximum %d\n",
+ "Value %u exceeds maximum %d\n",
dev_nack_retry_cnt, DW_I3C_DEV_NACK_RETRY_CNT_MAX);
return -ERANGE;
}
diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h
index f73cede87d36..6f0379bdbb6d 100644
--- a/include/linux/i3c/master.h
+++ b/include/linux/i3c/master.h
@@ -494,7 +494,7 @@ struct i3c_master_controller_ops {
int (*disable_hotjoin)(struct i3c_master_controller *master);
int (*set_speed)(struct i3c_master_controller *master, enum i3c_open_drain_speed speed);
int (*set_dev_nack_retry)(struct i3c_master_controller *master,
- unsigned long dev_nack_retry_cnt);
+ unsigned int dev_nack_retry_cnt);
};
/**
--
2.51.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] i3c: master: Update dev_nack_retry_count under maintenance lock
2026-06-16 11:37 ` [PATCH 1/3] i3c: master: Update dev_nack_retry_count under maintenance lock Adrian Hunter
@ 2026-06-16 16:55 ` Frank Li
0 siblings, 0 replies; 7+ messages in thread
From: Frank Li @ 2026-06-16 16:55 UTC (permalink / raw)
To: Adrian Hunter
Cc: alexandre.belloni, Frank.Li, Adrian Ng Ho Yin, linux-i3c,
linux-kernel
On Tue, Jun 16, 2026 at 02:37:50PM +0300, Adrian Hunter wrote:
> 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>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.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
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/3] i3c: master: Add missing runtime PM get in dev_nack_retry_count_store()
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 16:56 ` Frank Li
0 siblings, 0 replies; 7+ messages in thread
From: Frank Li @ 2026-06-16 16:56 UTC (permalink / raw)
To: Adrian Hunter
Cc: alexandre.belloni, Frank.Li, Adrian Ng Ho Yin, linux-i3c,
linux-kernel
On Tue, Jun 16, 2026 at 02:37:51PM +0300, Adrian Hunter wrote:
> Ensure the device is runtime resumed while updating the retry
> configuration to avoid accessing the controller while suspended.
>
> Call i3c_master_rpm_get() before accessing the controller in
> dev_nack_retry_count_store() and release it with
> i3c_master_rpm_put() afterwards.
>
> Fixes: 990c149c61ee4 ("i3c: master: Introduce optional Runtime PM support")
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> drivers/i3c/master.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index 66cf5d3bd987..903ac01ab413 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -767,12 +767,18 @@ static ssize_t dev_nack_retry_count_store(struct device *dev,
> if (ret)
> return ret;
>
> + ret = i3c_master_rpm_get(master);
> + if (ret)
> + return ret;
> +
> 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);
>
> + i3c_master_rpm_put(master);
> +
> return ret ?: count;
> }
>
> --
> 2.51.0
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] i3c: master: Use unsigned int for dev_nack_retry_count consistently
2026-06-16 11:37 ` [PATCH 3/3] i3c: master: Use unsigned int for dev_nack_retry_count consistently Adrian Hunter
@ 2026-06-16 16:58 ` Frank Li
0 siblings, 0 replies; 7+ messages in thread
From: Frank Li @ 2026-06-16 16:58 UTC (permalink / raw)
To: Adrian Hunter
Cc: alexandre.belloni, Frank.Li, Adrian Ng Ho Yin, linux-i3c,
linux-kernel
On Tue, Jun 16, 2026 at 02:37:52PM +0300, Adrian Hunter wrote:
> Use unsigned int for dev_nack_retry_count across the core and
> controller drivers to match the type of master->dev_nack_retry_count.
>
> Update the sysfs store path to use kstrtouint() and adjust the
> ->set_dev_nack_retry() callback prototype and callers accordingly.
>
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> drivers/i3c/master.c | 4 ++--
> drivers/i3c/master/dw-i3c-master.c | 4 ++--
> include/linux/i3c/master.h | 2 +-
> 3 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index 903ac01ab413..58d20624ed05 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -760,10 +760,10 @@ static ssize_t dev_nack_retry_count_store(struct device *dev,
> {
> struct i3c_bus *i3cbus = dev_to_i3cbus(dev);
> struct i3c_master_controller *master = dev_to_i3cmaster(dev);
> - unsigned long val;
> + unsigned int val;
> int ret;
>
> - ret = kstrtoul(buf, 0, &val);
> + ret = kstrtouint(buf, 0, &val);
> if (ret)
> return ret;
>
> diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
> index c7030d0cd8a6..e4f6d6f29ed5 100644
> --- a/drivers/i3c/master/dw-i3c-master.c
> +++ b/drivers/i3c/master/dw-i3c-master.c
> @@ -1481,7 +1481,7 @@ static irqreturn_t dw_i3c_master_irq_handler(int irq, void *dev_id)
> }
>
> static int dw_i3c_master_set_dev_nack_retry(struct i3c_master_controller *m,
> - unsigned long dev_nack_retry_cnt)
> + unsigned int dev_nack_retry_cnt)
> {
> struct dw_i3c_master *master = to_dw_i3c_master(m);
> u32 reg;
> @@ -1489,7 +1489,7 @@ static int dw_i3c_master_set_dev_nack_retry(struct i3c_master_controller *m,
>
> if (dev_nack_retry_cnt > DW_I3C_DEV_NACK_RETRY_CNT_MAX) {
> dev_err(&master->base.dev,
> - "Value %ld exceeds maximum %d\n",
> + "Value %u exceeds maximum %d\n",
> dev_nack_retry_cnt, DW_I3C_DEV_NACK_RETRY_CNT_MAX);
> return -ERANGE;
> }
> diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h
> index f73cede87d36..6f0379bdbb6d 100644
> --- a/include/linux/i3c/master.h
> +++ b/include/linux/i3c/master.h
> @@ -494,7 +494,7 @@ struct i3c_master_controller_ops {
> int (*disable_hotjoin)(struct i3c_master_controller *master);
> int (*set_speed)(struct i3c_master_controller *master, enum i3c_open_drain_speed speed);
> int (*set_dev_nack_retry)(struct i3c_master_controller *master,
> - unsigned long dev_nack_retry_cnt);
> + unsigned int dev_nack_retry_cnt);
> };
>
> /**
> --
> 2.51.0
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-06-16 16:58 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-16 11:37 [PATCH 0/3] i3c: master: Small fixes for dev_nack_retry_count Adrian Hunter
2026-06-16 11:37 ` [PATCH 1/3] i3c: master: Update dev_nack_retry_count under maintenance lock Adrian Hunter
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 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 16:58 ` Frank Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox