Skip to content

Commit

Permalink
i2c: ismt: Return EMSGSIZE for block reads with bogus length
Browse files Browse the repository at this point in the history
Compare the number of bytes actually seen on the wire to the byte
count field returned by the slave device.

Previously we just overwrote the byte count returned by the slave
with the real byte count and let the caller figure out if the
message was sane.

Signed-off-by: Stephen Douthit <stephend@adiengineering.com>
Tested-by: Dan Priamo <danp@adiengineering.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Cc: stable@kernel.org
  • Loading branch information
Stephen Douthit authored and Wolfram Sang committed Aug 29, 2017
1 parent b6c159a commit ba201c4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/i2c/busses/i2c-ismt.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,10 @@ static int ismt_process_desc(const struct ismt_desc *desc,
break;
case I2C_SMBUS_BLOCK_DATA:
case I2C_SMBUS_I2C_BLOCK_DATA:
if (desc->rxbytes != dma_buffer[0] + 1)
return -EMSGSIZE;

memcpy(data->block, dma_buffer, desc->rxbytes);
data->block[0] = desc->rxbytes - 1;
break;
}
return 0;
Expand Down

0 comments on commit ba201c4

Please sign in to comment.