diff options
-rw-r--r-- | 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 6d221e9fc..7be489036 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) | |||
724 | int res, blen = 0, tmp, i; | 724 | int res, blen = 0, tmp, i; |
725 | 725 | ||
726 | if (mode == I2C_SMBUS_BLOCK_DATA) { | 726 | if (mode == I2C_SMBUS_BLOCK_DATA) { |
727 | res = i2c_smbus_read_block_data(buf_fd, 0, cblock); | 727 | blen = i2c_smbus_read_block_data(buf_fd, 0, cblock); |
728 | blen = res; | 728 | if (blen <= 0) |
729 | goto fail; | ||
729 | } else { | 730 | } else { |
730 | for (res = 0; res < I2CDUMP_NUM_REGS; res += tmp) { | 731 | for (res = 0; res < I2CDUMP_NUM_REGS; res += tmp) { |
731 | tmp = i2c_smbus_read_i2c_block_data( | 732 | tmp = i2c_smbus_read_i2c_block_data( |
732 | buf_fd, res, I2C_SMBUS_BLOCK_MAX, | 733 | buf_fd, res, I2C_SMBUS_BLOCK_MAX, |
733 | cblock + res); | 734 | cblock + res); |
734 | if (tmp < 0) { | 735 | if (tmp <= 0) |
735 | bb_error_msg_and_die("block read failed"); | 736 | goto fail; |
736 | } | ||
737 | } | 737 | } |
738 | 738 | ||
739 | if (res >= I2CDUMP_NUM_REGS) | 739 | if (res >= I2CDUMP_NUM_REGS) |
@@ -748,6 +748,9 @@ static int read_block_data(int buf_fd, int mode, int *block) | |||
748 | } | 748 | } |
749 | 749 | ||
750 | return blen; | 750 | return blen; |
751 | |||
752 | fail: | ||
753 | bb_error_msg_and_die("block read failed"); | ||
751 | } | 754 | } |
752 | 755 | ||
753 | /* Dump all but word data. */ | 756 | /* Dump all but word data. */ |