All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] libi2c: Use I2C_SMBUS_BLOCK_MAX
@ 2012-06-22 14:59 Jean Delvare
  0 siblings, 0 replies; only message in thread
From: Jean Delvare @ 2012-06-22 14:59 UTC (permalink / raw)
  To: Linux I2C

Use I2C_SMBUS_BLOCK_MAX instead of hardcoding 32.

---
 lib/smbus.c |   25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

--- i2c-tools.orig/lib/smbus.c	2012-06-22 16:09:54.426235336 +0200
+++ i2c-tools/lib/smbus.c	2012-06-22 16:10:18.169262240 +0200
@@ -151,8 +151,8 @@ __s32 i2c_smbus_write_block_data(int fil
 {
 	union i2c_smbus_data data;
 	int i;
-	if (length > 32)
-		length = 32;
+	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;
@@ -161,21 +161,22 @@ __s32 i2c_smbus_write_block_data(int fil
 }
 
 /* Returns the number of read bytes */
-/* Until kernel 2.6.22, the length is hardcoded to 32 bytes. If you
-   ask for less than 32 bytes, your code will only work with kernels
-   2.6.23 and later. */
+/* Until kernel 2.6.22, the length is hardcoded to 32 bytes
+   (I2C_SMBUS_BLOCK_MAX.) If you ask for less than 32 bytes, your code
+   will only work with kernels 2.6.23 and later. */
 __s32 i2c_smbus_read_i2c_block_data(int file, __u8 command, __u8 length,
 				    __u8 *values)
 {
 	union i2c_smbus_data data;
 	int i, err;
 
-	if (length > 32)
-		length = 32;
+	if (length > I2C_SMBUS_BLOCK_MAX)
+		length = I2C_SMBUS_BLOCK_MAX;
 	data.block[0] = length;
 
 	err = i2c_smbus_access(file, I2C_SMBUS_READ, command,
-			       length == 32 ? I2C_SMBUS_I2C_BLOCK_BROKEN :
+			       length == I2C_SMBUS_BLOCK_MAX ?
+				I2C_SMBUS_I2C_BLOCK_BROKEN :
 				I2C_SMBUS_I2C_BLOCK_DATA, &data);
 	if (err < 0)
 		return err;
@@ -190,8 +191,8 @@ __s32 i2c_smbus_write_i2c_block_data(int
 {
 	union i2c_smbus_data data;
 	int i;
-	if (length > 32)
-		length = 32;
+	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;
@@ -206,8 +207,8 @@ __s32 i2c_smbus_block_process_call(int f
 	union i2c_smbus_data data;
 	int i, err;
 
-	if (length > 32)
-		length = 32;
+	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;


-- 
Jean Delvare

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2012-06-22 14:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-22 14:59 [PATCH 2/2] libi2c: Use I2C_SMBUS_BLOCK_MAX Jean Delvare

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.