Merge branch 'i2c/for-4.20' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa...
[muen/linux.git] / drivers / i2c / i2c-core-base.c
index 9200e349f29e411d53d2dc4126ea2f7a450a9288..dc78aa7369def416898f0a4c514fd017c147f0c0 100644 (file)
@@ -1922,6 +1922,11 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 {
        int ret;
 
+       if (!adap->algo->master_xfer) {
+               dev_dbg(&adap->dev, "I2C level transfers not supported\n");
+               return -EOPNOTSUPP;
+       }
+
        /* REVISIT the fault reporting model here is weak:
         *
         *  - When we get an error after receiving N bytes from a slave,
@@ -1938,35 +1943,19 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
         *    one (discarding status on the second message) or errno
         *    (discarding status on the first one).
         */
-
-       if (adap->algo->master_xfer) {
-#ifdef DEBUG
-               for (ret = 0; ret < num; ret++) {
-                       dev_dbg(&adap->dev,
-                               "master_xfer[%d] %c, addr=0x%02x, len=%d%s\n",
-                               ret, (msgs[ret].flags & I2C_M_RD) ? 'R' : 'W',
-                               msgs[ret].addr, msgs[ret].len,
-                               (msgs[ret].flags & I2C_M_RECV_LEN) ? "+" : "");
-               }
-#endif
-
-               if (in_atomic() || irqs_disabled()) {
-                       ret = i2c_trylock_bus(adap, I2C_LOCK_SEGMENT);
-                       if (!ret)
-                               /* I2C activity is ongoing. */
-                               return -EAGAIN;
-               } else {
-                       i2c_lock_bus(adap, I2C_LOCK_SEGMENT);
-               }
-
-               ret = __i2c_transfer(adap, msgs, num);
-               i2c_unlock_bus(adap, I2C_LOCK_SEGMENT);
-
-               return ret;
+       if (in_atomic() || irqs_disabled()) {
+               ret = i2c_trylock_bus(adap, I2C_LOCK_SEGMENT);
+               if (!ret)
+                       /* I2C activity is ongoing. */
+                       return -EAGAIN;
        } else {
-               dev_dbg(&adap->dev, "I2C level transfers not supported\n");
-               return -EOPNOTSUPP;
+               i2c_lock_bus(adap, I2C_LOCK_SEGMENT);
        }
+
+       ret = __i2c_transfer(adap, msgs, num);
+       i2c_unlock_bus(adap, I2C_LOCK_SEGMENT);
+
+       return ret;
 }
 EXPORT_SYMBOL(i2c_transfer);