]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
i2c: core: apply 'is_suspended' check for SMBus, too
authorWolfram Sang <wsa+renesas@sang-engineering.com>
Thu, 25 Apr 2019 14:19:48 +0000 (16:19 +0200)
committerWolfram Sang <wsa@the-dreams.de>
Fri, 3 May 2019 14:44:51 +0000 (16:44 +0200)
We checked I2C calls, but not SMBus. Refactor the helper to an inline
function and use it for both, I2C and SMBus.

Fixes: 9ac6cb5fbb17 ("i2c: add suspended flag and accessors for i2c adapters")
Reported-by: Peter Rosin <peda@axentia.se>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Simon Horman <horms+renesas@verge.net.au>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
drivers/i2c/i2c-core-base.c
drivers/i2c/i2c-core-smbus.c
drivers/i2c/i2c-core.h

index f8e85983cb04d0276f194539ebc912dbf3b0e9a0..f7ae416f1e08c82830a1cdfc58223f41c4237421 100644 (file)
@@ -1867,11 +1867,10 @@ int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 
        if (WARN_ON(!msgs || num < 1))
                return -EINVAL;
-       if (test_bit(I2C_ALF_IS_SUSPENDED, &adap->locked_flags)) {
-               if (!test_and_set_bit(I2C_ALF_SUSPEND_REPORTED, &adap->locked_flags))
-                       dev_WARN(&adap->dev, "Transfer while suspended\n");
-               return -ESHUTDOWN;
-       }
+
+       ret = __i2c_check_suspended(adap);
+       if (ret)
+               return ret;
 
        if (adap->quirks && i2c_check_for_quirks(adap, msgs, num))
                return -EOPNOTSUPP;
index fdb0fb9fb9aab660e2ae4b1ed0a2942d348e0dca..788d42f2aad9e6bd591611ba207ad26749f2ef72 100644 (file)
@@ -555,6 +555,10 @@ s32 __i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
        int try;
        s32 res;
 
+       res = __i2c_check_suspended(adapter);
+       if (res)
+               return res;
+
        /* If enabled, the following two tracepoints are conditional on
         * read_write and protocol.
         */
index f9d0c417b5a56061695e82abb781ae162c0113ae..c88cfef813431da66454c681e6546877df2266c3 100644 (file)
@@ -54,6 +54,17 @@ static inline int __i2c_lock_bus_helper(struct i2c_adapter *adap)
        return ret;
 }
 
+static inline int __i2c_check_suspended(struct i2c_adapter *adap)
+{
+       if (test_bit(I2C_ALF_IS_SUSPENDED, &adap->locked_flags)) {
+               if (!test_and_set_bit(I2C_ALF_SUSPEND_REPORTED, &adap->locked_flags))
+                       dev_WARN(&adap->dev, "Transfer while suspended\n");
+               return -ESHUTDOWN;
+       }
+
+       return 0;
+}
+
 #ifdef CONFIG_ACPI
 const struct acpi_device_id *
 i2c_acpi_match_device(const struct acpi_device_id *matches,