i2c: slave-eeprom: add more info when to increase the pointer
authorWolfram Sang <wsa+renesas@sang-engineering.com>
Mon, 23 Mar 2015 08:26:39 +0000 (09:26 +0100)
committerWolfram Sang <wsa@the-dreams.de>
Fri, 27 Mar 2015 15:53:40 +0000 (16:53 +0100)
It is a bit subtle when to correctly increase the buffer index when
reading. Make this clearer by adding some more comments and pointers to
the docs.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
drivers/i2c/i2c-slave-eeprom.c

index 3fb45d894d80721aaa3ced67d8e6adda6b888814..8223746546093c7a08f4bdfc8425459d88fe1a52 100644 (file)
@@ -48,12 +48,18 @@ static int i2c_slave_eeprom_slave_cb(struct i2c_client *client,
                break;
 
        case I2C_SLAVE_READ_PROCESSED:
+               /* The previous byte made it to the bus, get next one */
                eeprom->buffer_idx++;
                /* fallthrough */
        case I2C_SLAVE_READ_REQUESTED:
                spin_lock(&eeprom->buffer_lock);
                *val = eeprom->buffer[eeprom->buffer_idx];
                spin_unlock(&eeprom->buffer_lock);
+               /*
+                * Do not increment buffer_idx here, because we don't know if
+                * this byte will be actually used. Read Linux I2C slave docs
+                * for details.
+                */
                break;
 
        case I2C_SLAVE_STOP: