[PATCH 1/3] i3c: master: Update dev_nack_retry_count under maintenance lock

Frank Li Frank.li at oss.nxp.com
Tue Jun 16 09:55:47 PDT 2026


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 at intel.com>
> ---

Reviewed-by: Frank Li <Frank.Li at 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
>



More information about the linux-i3c mailing list