leds: leds-lp5562 allow firmware files up to the maximum length
authorNick Stoughton <nstoughton@logitech.com>
Wed, 17 Jul 2019 21:56:06 +0000 (14:56 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 5 Oct 2019 10:47:45 +0000 (12:47 +0200)
[ Upstream commit ed2abfebb041473092b41527903f93390d38afa7 ]

Firmware files are in ASCII, using 2 hex characters per byte. The
maximum length of a firmware string is therefore

16 (commands) * 2 (bytes per command) * 2 (characters per byte) = 64

Fixes: ff45262a85db ("leds: add new LP5562 LED driver")
Signed-off-by: Nick Stoughton <nstoughton@logitech.com>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/leds/leds-lp5562.c

index 05ffa34fb6ad0dc41f3afc18754a87aacb36a6c6..9d9b673c873c625da6e36473cf15855b4364b536 100644 (file)
@@ -263,7 +263,11 @@ static void lp5562_firmware_loaded(struct lp55xx_chip *chip)
 {
        const struct firmware *fw = chip->fw;
 
-       if (fw->size > LP5562_PROGRAM_LENGTH) {
+       /*
+        * the firmware is encoded in ascii hex character, with 2 chars
+        * per byte
+        */
+       if (fw->size > (LP5562_PROGRAM_LENGTH * 2)) {
                dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n",
                        fw->size);
                return;