i2c: core: use I2C locking behaviour also for SMBUS
[linux-block.git] / drivers / i2c / i2c-core-base.c
index cb6c5cb0df0b3d5438521127110940b8f4cc56f8..ad14f38a67e4ac91862948c1ae5ae9ab1d835de2 100644 (file)
@@ -1946,14 +1946,9 @@ 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 (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_lock_bus_helper(adap);
+       if (ret)
+               return ret;
 
        ret = __i2c_transfer(adap, msgs, num);
        i2c_unlock_bus(adap, I2C_LOCK_SEGMENT);
@@ -2258,7 +2253,8 @@ EXPORT_SYMBOL(i2c_put_adapter);
 /**
  * i2c_get_dma_safe_msg_buf() - get a DMA safe buffer for the given i2c_msg
  * @msg: the message to be checked
- * @threshold: the minimum number of bytes for which using DMA makes sense
+ * @threshold: the minimum number of bytes for which using DMA makes sense.
+ *            Should at least be 1.
  *
  * Return: NULL if a DMA safe buffer was not obtained. Use msg->buf with PIO.
  *        Or a valid pointer to be used with DMA. After use, release it by
@@ -2268,7 +2264,11 @@ EXPORT_SYMBOL(i2c_put_adapter);
  */
 u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold)
 {
-       if (msg->len < threshold)
+       /* also skip 0-length msgs for bogus thresholds of 0 */
+       if (!threshold)
+               pr_debug("DMA buffer for addr=0x%02x with length 0 is bogus\n",
+                        msg->addr);
+       if (msg->len < threshold || msg->len == 0)
                return NULL;
 
        if (msg->flags & I2C_M_DMA_SAFE)