[git commit] i2cdump: bail-out if block read fails

Denys Vlasenko vda.linux at googlemail.com
Sun Nov 1 19:55:09 UTC 2015


commit: http://git.busybox.net/busybox/commit/?id=74bb9d5e63b0928ceac57fedd4a2d383129ade7d
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

We should bail-out if i2c_smbus_read_block_data() or
i2c_smbus_read_i2c_block_data() return 0 or less. Add the missing check
for the former and fix the existing for the latter.

Signed-off-by: Bartosz Golaszewski <bartekgola at gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 miscutils/i2c_tools.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/miscutils/i2c_tools.c b/miscutils/i2c_tools.c
index 6d221e9..7be4890 100644
--- a/miscutils/i2c_tools.c
+++ b/miscutils/i2c_tools.c
@@ -724,16 +724,16 @@ static int read_block_data(int buf_fd, int mode, int *block)
 	int res, blen = 0, tmp, i;
 
 	if (mode == I2C_SMBUS_BLOCK_DATA) {
-		res = i2c_smbus_read_block_data(buf_fd, 0, cblock);
-		blen = res;
+		blen = i2c_smbus_read_block_data(buf_fd, 0, cblock);
+		if (blen <= 0)
+			goto fail;
 	} else {
 		for (res = 0; res < I2CDUMP_NUM_REGS; res += tmp) {
 			tmp = i2c_smbus_read_i2c_block_data(
 					buf_fd, res, I2C_SMBUS_BLOCK_MAX,
 					cblock + res);
-			if (tmp < 0) {
-				bb_error_msg_and_die("block read failed");
-			}
+			if (tmp <= 0)
+				goto fail;
 		}
 
 		if (res >= I2CDUMP_NUM_REGS)
@@ -748,6 +748,9 @@ static int read_block_data(int buf_fd, int mode, int *block)
 	}
 
 	return blen;
+
+ fail:
+	bb_error_msg_and_die("block read failed");
 }
 
 /* Dump all but word data. */


More information about the busybox-cvs mailing list