Re: [PATCH v7 1/2] i2c: algo: bit: Allow to skip bit test
From: Bartosz Golaszewski
Date: Thu Jul 16 2026 - 04:17:23 EST
On Tue, 14 Jul 2026 18:29:14 +0200, Markus Stockhausen
<markus.stockhausen@xxxxxx> said:
> An I2C bus can make use of shared resources. E.g. two GPIO based buses
> that share a single SCL line. To synchronize access to the bus the driver
> might use locking with the help of i2c_lock_operations(). While this
> works for normal transfers it is not available during initialization.
>
> Especially if i2c-algo-bit module is loaded with parameter bit_test
> it will issue some basic sanity checks that will access the bus without
> locking. This might interfere badly with concurrent transfers. Even
> if these are well synchronized via locks.
>
> Allow the consumer of an algorithm to override if the bit_test is allowed
> or not. For this add a new boolean attribute named skip_bit_test to
> i2c_algo_bit_data. If set the test is not run.
>
> Signed-off-by: Markus Stockhausen <markus.stockhausen@xxxxxx>
> ---
> drivers/i2c/algos/i2c-algo-bit.c | 2 +-
> include/linux/i2c-algo-bit.h | 1 +
> 2 files changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
> index d1d9a6c1a1e2..7ca565cbff5b 100644
> --- a/drivers/i2c/algos/i2c-algo-bit.c
> +++ b/drivers/i2c/algos/i2c-algo-bit.c
> @@ -639,7 +639,7 @@ static int __i2c_bit_add_bus(struct i2c_adapter *adap,
> struct i2c_algo_bit_data *bit_adap = adap->algo_data;
> int ret;
>
> - if (bit_test) {
> + if (bit_test && !bit_adap->skip_bit_test) {
> ret = test_bus(adap);
> if (bit_test >= 2 && ret < 0)
> return -ENODEV;
> diff --git a/include/linux/i2c-algo-bit.h b/include/linux/i2c-algo-bit.h
> index 7fd5575a368f..c4c43aec1e67 100644
> --- a/include/linux/i2c-algo-bit.h
> +++ b/include/linux/i2c-algo-bit.h
> @@ -34,6 +34,7 @@ struct i2c_algo_bit_data {
> maximum 50 us for SMBus */
> int timeout; /* in jiffies */
> bool can_do_atomic; /* callbacks don't sleep, we can be atomic */
> + bool skip_bit_test; /* override bit_test module parameter */
> };
>
> int i2c_bit_add_bus(struct i2c_adapter *);
> --
> 2.54.0
>
>
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>