drm/i915/intel_i2c: handle zero-length writes
authorDaniel Kurtz <djkurtz@chromium.org>
Fri, 30 Mar 2012 11:46:36 +0000 (19:46 +0800)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Thu, 12 Apr 2012 19:14:06 +0000 (21:14 +0200)
A common method of probing an i2c bus is trying to do a zero-length write.
Handle this case by checking the length first before decrementing it.

This is actually important, since attempting a zero-length write is one
of the ways that i2cdetect and i2c_new_probed_device detect whether
there is device present on the bus with a given address.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
drivers/gpu/drm/i915/intel_i2c.c

index c12db7265893995bf2580b22f10a0c7b586adf4c..99a04f8bcb1f6f4e92fde7414cd5bae7122b7cbe 100644 (file)
@@ -248,9 +248,10 @@ gmbus_xfer_write(struct drm_i915_private *dev_priv, struct i2c_msg *msg,
        u32 val, loop;
 
        val = loop = 0;
-       do {
-               val |= *buf++ << (8 * loop);
-       } while (--len && ++loop < 4);
+       while (len && loop < 4) {
+               val |= *buf++ << (8 * loop++);
+               len -= 1;
+       }
 
        I915_WRITE(GMBUS3 + reg_offset, val);
        I915_WRITE(GMBUS1 + reg_offset,