Message ID | 20240606203657.22286-2-wsa+renesas@sang-engineering.com |
---|---|
State | New |
Headers | show |
Series | i2c: complain loudly if __i2c_transfer has no proper callback | expand |
Hi Wolfram, On Thu, 6 Jun 2024 22:36:58 +0200, Wolfram Sang wrote: > In a discussion we concluded that having no working callback in > __i2c_transfer is a serious bug, so dev_dbg() is not enough. Turn it > into a WARN. > > Link: https://lore.kernel.org/r/20240604171113.232628f9@endymion.delvare > Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> > --- > drivers/i2c/i2c-core-base.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c > index db0d1ac82910..e5fd899c28c3 100644 > --- a/drivers/i2c/i2c-core-base.c > +++ b/drivers/i2c/i2c-core-base.c > @@ -2207,10 +2207,8 @@ int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) > unsigned long orig_jiffies; > int ret, try; > > - if (!adap->algo->master_xfer) { > - dev_dbg(&adap->dev, "I2C level transfers not supported\n"); > + if (WARN_ON_ONCE(!adap->algo->master_xfer)) > return -EOPNOTSUPP; > - } > > if (WARN_ON(!msgs || num < 1)) > return -EINVAL; Then you'll have to add a check on I2C_FUNC_I2C (or adapter->algo->master_xfer, whatever you prefer) before calling i2c_smbus_xfer_emulated(). Otherwise using i2c-dev on a slave-only adapter will trigger the WARN_ON_ONCE immediately.
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index db0d1ac82910..e5fd899c28c3 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -2207,10 +2207,8 @@ int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) unsigned long orig_jiffies; int ret, try; - if (!adap->algo->master_xfer) { - dev_dbg(&adap->dev, "I2C level transfers not supported\n"); + if (WARN_ON_ONCE(!adap->algo->master_xfer)) return -EOPNOTSUPP; - } if (WARN_ON(!msgs || num < 1)) return -EINVAL;
In a discussion we concluded that having no working callback in __i2c_transfer is a serious bug, so dev_dbg() is not enough. Turn it into a WARN. Link: https://lore.kernel.org/r/20240604171113.232628f9@endymion.delvare Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> --- drivers/i2c/i2c-core-base.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)