Skip to content

Commit

Permalink
watchdog: ziirave_wdt: Don't read out more than 'len' firmware bytes
Browse files Browse the repository at this point in the history
We only compare first 'len' bytes of read firmware, so we don't need
to read more that that.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Chris Healy <cphealy@gmail.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Rick Ramstetter <rick@anteaterllc.com>
Cc: linux-watchdog@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Link: https://lore.kernel.org/r/20190812200906.31344-14-andrew.smirnov@gmail.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
  • Loading branch information
Andrey Smirnov authored and Wim Van Sebroeck committed Sep 17, 2019
1 parent d91bb8d commit de88053
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/watchdog/ziirave_wdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ static int ziirave_firm_verify(struct watchdog_device *wdd,
u16 addr;

for (rec = (void *)fw->data; rec; rec = ihex_next_binrec(rec)) {
const u16 len = be16_to_cpu(rec->len);

addr = (be32_to_cpu(rec->addr) & 0xffff) >> 1;
if (addr < ZIIRAVE_FIRM_FLASH_MEMORY_START ||
addr > ZIIRAVE_FIRM_FLASH_MEMORY_END)
Expand All @@ -331,7 +333,7 @@ static int ziirave_firm_verify(struct watchdog_device *wdd,
return ret;
}

for (i = 0; i < ARRAY_SIZE(data); i++) {
for (i = 0; i < len; i++) {
ret = i2c_smbus_read_byte_data(client,
ZIIRAVE_CMD_DOWNLOAD_READ_BYTE);
if (ret < 0) {
Expand All @@ -342,7 +344,7 @@ static int ziirave_firm_verify(struct watchdog_device *wdd,
data[i] = ret;
}

if (memcmp(data, rec->data, be16_to_cpu(rec->len))) {
if (memcmp(data, rec->data, len)) {
dev_err(&client->dev,
"Firmware mismatch at address 0x%04x\n", addr);
return -EINVAL;
Expand Down

0 comments on commit de88053

Please sign in to comment.