[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20221115083555.22928-1-hucool.lihua@huawei.com>
Date: Tue, 15 Nov 2022 16:35:55 +0800
From: Li Hua <hucool.lihua@...wei.com>
To: <wim@...ux-watchdog.org>, <linux@...ck-us.net>
CC: <linux-watchdog@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<weiyongjun1@...wei.com>, <yusongping@...wei.com>,
<hucool.lihua@...wei.com>
Subject: [PATCH] watchdog: pcwd_usb: Fix attempting to access uninitialized memory
The stack variable msb and lsb may be used uninitialized in function
usb_pcwd_get_temperature and usb_pcwd_get_timeleft when usb card no response.
The build waring is:
drivers/watchdog/pcwd_usb.c:336:22: error: ‘lsb’ is used uninitialized in this function [-Werror=uninitialized]
*temperature = (lsb * 9 / 5) + 32;
~~~~^~~
drivers/watchdog/pcwd_usb.c:328:21: note: ‘lsb’ was declared here
unsigned char msb, lsb;
^~~
cc1: all warnings being treated as errors
scripts/Makefile.build:250: recipe for target 'drivers/watchdog/pcwd_usb.o' failed
make[3]: *** [drivers/watchdog/pcwd_usb.o] Error 1
Fixes: b7e04f8c61a4 ("mv watchdog tree under drivers")
Signed-off-by: Li Hua <hucool.lihua@...wei.com>
---
drivers/watchdog/pcwd_usb.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/drivers/watchdog/pcwd_usb.c b/drivers/watchdog/pcwd_usb.c
index 1bdaf17c1d38..89b0b5d8a7e6 100644
--- a/drivers/watchdog/pcwd_usb.c
+++ b/drivers/watchdog/pcwd_usb.c
@@ -326,8 +326,13 @@ static int usb_pcwd_get_temperature(struct usb_pcwd_private *usb_pcwd,
int *temperature)
{
unsigned char msb, lsb;
+ int retval;
- usb_pcwd_send_command(usb_pcwd, CMD_READ_TEMP, &msb, &lsb);
+ retval = usb_pcwd_send_command(usb_pcwd, CMD_READ_TEMP, &msb, &lsb);
+ if (retval != 1) {
+ pr_err("Card did not acknowledge CMD_READ_TEMP\n");
+ return -1;
+ }
/*
* Convert celsius to fahrenheit, since this was
@@ -342,10 +347,16 @@ static int usb_pcwd_get_timeleft(struct usb_pcwd_private *usb_pcwd,
int *time_left)
{
unsigned char msb, lsb;
+ int retval;
/* Read the time that's left before rebooting */
/* Note: if the board is not yet armed then we will read 0xFFFF */
- usb_pcwd_send_command(usb_pcwd, CMD_READ_WATCHDOG_TIMEOUT, &msb, &lsb);
+ retval = usb_pcwd_send_command(usb_pcwd, CMD_READ_WATCHDOG_TIMEOUT,
+ &msb, &lsb);
+ if (retval != 1) {
+ pr_err("Card did not acknowledge CMD_READ_WATCHDOG_TIMEOUT\n");
+ return -1;
+ }
*time_left = (msb << 8) + lsb;
--
2.17.1
Powered by blists - more mailing lists