lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250621091757.16926-1-abd.masalkhi@gmail.com>
Date: Sat, 21 Jun 2025 09:17:57 +0000
From: Abd-Alrhman Masalkhi <abd.masalkhi@...il.com>
To: abd.masalkhi@...il.com
Cc: linux-i2c@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	wsa+renesas@...g-engineering.com
Subject: Re: [PATCH] i2c: core: Serialize 10-bit client instantiation with mutex

Hi all,

Gentle ping.

Best regards,
Abd-Alrhman Masalkhi

On 2025/6/14 08:37, Abd-Alrhman Masalkhi wrote:
> Add a mutex to protect against race conditions when instantiating
> 10-bit address I2C clients. It serves the same purpose as the 7-bit
> address bitmap (addrs_in_instantiation), but uses a mutex instead,
> since 10-bit clients are rare and a full bitmap would unnecessarily
> increase the size of struct i2c_adapter.
> 
> Signed-off-by: Abd-Alrhman Masalkhi <abd.masalkhi@...il.com>
> ---
>  drivers/i2c/i2c-core-base.c | 8 +++++++-
>  include/linux/i2c.h         | 3 +++
>  2 files changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index 2ad2b1838f0f..f5f53d378fff 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -929,6 +929,9 @@ int i2c_dev_irq_from_resources(const struct resource *resources,
>  static int i2c_lock_addr(struct i2c_adapter *adap, unsigned short addr,
>  			 unsigned short flags)
>  {
> +	if (flags & I2C_CLIENT_TEN)
> +		mutex_lock(&adap->addrs_10bit_lock);
> +
>  	if (!(flags & I2C_CLIENT_TEN) &&
>  	    test_and_set_bit(addr, adap->addrs_in_instantiation))
>  		return -EBUSY;
> @@ -939,7 +942,9 @@ static int i2c_lock_addr(struct i2c_adapter *adap, unsigned short addr,
>  static void i2c_unlock_addr(struct i2c_adapter *adap, unsigned short addr,
>  			    unsigned short flags)
>  {
> -	if (!(flags & I2C_CLIENT_TEN))
> +	if (flags & I2C_CLIENT_TEN)
> +		mutex_unlock(&adap->addrs_10bit_lock);
> +	else
>  		clear_bit(addr, adap->addrs_in_instantiation);
>  }
>  
> @@ -1538,6 +1543,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
>  	adap->locked_flags = 0;
>  	rt_mutex_init(&adap->bus_lock);
>  	rt_mutex_init(&adap->mux_lock);
> +	mutex_init(&adap->addrs_10bit_lock);
>  	mutex_init(&adap->userspace_clients_lock);
>  	INIT_LIST_HEAD(&adap->userspace_clients);
>  
> diff --git a/include/linux/i2c.h b/include/linux/i2c.h
> index 20fd41b51d5c..1d4d0577b5b1 100644
> --- a/include/linux/i2c.h
> +++ b/include/linux/i2c.h
> @@ -765,6 +765,9 @@ struct i2c_adapter {
>  
>  	/* 7bit address space */
>  	DECLARE_BITMAP(addrs_in_instantiation, 1 << 7);
> +
> +	/* Lock for 10bit address instantiation */
> +	struct mutex addrs_10bit_lock;
>  };
>  #define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)
>  
> -- 
> 2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ