[PATCH] i2c: Speed up block transfers
authorJean Delvare <khali@linux-fr.org>
Wed, 18 Jan 2006 22:14:55 +0000 (23:14 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Thu, 23 Mar 2006 22:21:51 +0000 (14:21 -0800)
Speed up i2c_smbus_write_block_data and i2c_smbus_read_i2c_block_data
a bit by using memcpy instead of an explicit loop.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/i2c/i2c-core.c

index 97334433e534cd1f72354a742b152a5a0b1ed78c..2b0c555aa0117382a9319a03ec7f84358e5ccb51 100644 (file)
@@ -920,12 +920,11 @@ s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command,
                               u8 length, u8 *values)
 {
        union i2c_smbus_data data;
-       int i;
+
        if (length > I2C_SMBUS_BLOCK_MAX)
                length = I2C_SMBUS_BLOCK_MAX;
-       for (i = 1; i <= length; i++)
-               data.block[i] = values[i-1];
        data.block[0] = length;
+       memcpy(&data.block[1], values, length);
        return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
                              I2C_SMBUS_WRITE,command,
                              I2C_SMBUS_BLOCK_DATA,&data);
@@ -935,16 +934,14 @@ s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command,
 s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command, u8 *values)
 {
        union i2c_smbus_data data;
-       int i;
+
        if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
                              I2C_SMBUS_READ,command,
                              I2C_SMBUS_I2C_BLOCK_DATA,&data))
                return -1;
-       else {
-               for (i = 1; i <= data.block[0]; i++)
-                       values[i-1] = data.block[i];
-               return data.block[0];
-       }
+
+       memcpy(values, &data.block[1], data.block[0]);
+       return data.block[0];
 }
 
 s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, u8 command,