i2cdump: bail-out if block read fails
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@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
1fe75b8ef1
commit
74bb9d5e63
@ -724,16 +724,16 @@ static int read_block_data(int buf_fd, int mode, int *block)
|
|||||||
int res, blen = 0, tmp, i;
|
int res, blen = 0, tmp, i;
|
||||||
|
|
||||||
if (mode == I2C_SMBUS_BLOCK_DATA) {
|
if (mode == I2C_SMBUS_BLOCK_DATA) {
|
||||||
res = i2c_smbus_read_block_data(buf_fd, 0, cblock);
|
blen = i2c_smbus_read_block_data(buf_fd, 0, cblock);
|
||||||
blen = res;
|
if (blen <= 0)
|
||||||
|
goto fail;
|
||||||
} else {
|
} else {
|
||||||
for (res = 0; res < I2CDUMP_NUM_REGS; res += tmp) {
|
for (res = 0; res < I2CDUMP_NUM_REGS; res += tmp) {
|
||||||
tmp = i2c_smbus_read_i2c_block_data(
|
tmp = i2c_smbus_read_i2c_block_data(
|
||||||
buf_fd, res, I2C_SMBUS_BLOCK_MAX,
|
buf_fd, res, I2C_SMBUS_BLOCK_MAX,
|
||||||
cblock + res);
|
cblock + res);
|
||||||
if (tmp < 0) {
|
if (tmp <= 0)
|
||||||
bb_error_msg_and_die("block read failed");
|
goto fail;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res >= I2CDUMP_NUM_REGS)
|
if (res >= I2CDUMP_NUM_REGS)
|
||||||
@ -748,6 +748,9 @@ static int read_block_data(int buf_fd, int mode, int *block)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return blen;
|
return blen;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
bb_error_msg_and_die("block read failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Dump all but word data. */
|
/* Dump all but word data. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user