watchdog: ziirave_wdt: Skip zeros when calculating checksum
authorAndrey Smirnov <andrew.smirnov@gmail.com>
Mon, 12 Aug 2019 20:08:52 +0000 (13:08 -0700)
committerWim Van Sebroeck <wim@linux-watchdog.org>
Tue, 17 Sep 2019 06:59:05 +0000 (08:59 +0200)
Zeros don't contribute anything to checksum value, so we can skip
unused portion of the packet when calculating its checksum.

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-9-andrew.smirnov@gmail.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
drivers/watchdog/ziirave_wdt.c

index 9d9c669b8b47da40a16b721c4279dbe6ef55dee2..19da0910c2d12ea9e821b43192b04d40efceced8 100644 (file)
@@ -271,7 +271,7 @@ static int __ziirave_firm_write_pkt(struct watchdog_device *wdd,
        memcpy(packet + 3, data, len);
 
        /* Packet checksum */
-       for (i = 0; i < ZIIRAVE_FIRM_PKT_TOTAL_SIZE - 1; i++)
+       for (i = 0; i < len + 3; i++)
                checksum += packet[i];
        packet[ZIIRAVE_FIRM_PKT_TOTAL_SIZE - 1] = checksum;