From patchwork Tue Nov 15 08:35:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Lihua (lihua, ran)" X-Patchwork-Id: 20235 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2582552wru; Tue, 15 Nov 2022 00:11:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf6T855gnGoDFrjvzuNmLGLMbVBS3FT23E/D+/lpf7lr8PEhpxgLaIGQPOPMTGoXQykwIRyx X-Received: by 2002:a17:902:ef48:b0:186:c589:9ed3 with SMTP id e8-20020a170902ef4800b00186c5899ed3mr3102682plx.52.1668499897891; Tue, 15 Nov 2022 00:11:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668499897; cv=none; d=google.com; s=arc-20160816; b=uAL3Xj4IKw77ryAs5zCnf5y2cIwbM/vI06LkAElbiMhEPIQYOWouFLcUA3vrSMDaoS IbMSYAzzCU2RxEdYwqqHXUbnryvAMNW2eQvuA0HuneTf0qDYFkEup2XuNUoDtsOzY5Q4 qJOZVb/XeXGYr+5aL/meaBNsPgr96r6+8PMlS4DXlNFNwoJ+SLchYMrq+pRJlin1TVyv iBD/flvjVDHw6IJHeJ8EdVRoP8BjQyjEA8mAXpbDblSSDDRah5WQfyzd2NPfu6LrqEJg FszXEj4lSO+HKHh83ZCbsXiUd9GVzS4lhl35tsAJqwVwYDdDgmdU611jiD6Do5lKYag9 L/qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=/VO549xY9iSfUFbvbB1ZUZsLlYoMX83LIjYYyDjbnsM=; b=buyJVcAgY1jl1F3pBkf/sS7Ye3iG1KXOi7q7SPz9G1e6dm4VqkV/ED7Nf/hy9JEdgq F9rsVAIcuQBEKG33pR4gb4Msj5StD+YZGWwN8Zmu75WAN5ZkmxLwzoA6IZhcSBlHDYLh qZH9OjND5dGIe7WIkhGhelAriYGxKVHcPw4+NnkdQDdH/4vWiADr3u0LQEK5p/BPQHaE l1o14HD9mMno2wKZYS9D1yZYzhYD6o5grKhtyMejY9N9VHGFnWcwTdKZC/gzdAtfijeH X5lx7BF0zMB0ZTilb/21JV7rexYjUVebOIQSWnGLSjVTI8a9r2Kq4511S4YxpwNqLBXa yYQg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f5-20020a17090274c500b00186f25708f4si10729973plt.241.2022.11.15.00.11.23; Tue, 15 Nov 2022 00:11:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232197AbiKOIHP (ORCPT + 99 others); Tue, 15 Nov 2022 03:07:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229585AbiKOIHN (ORCPT ); Tue, 15 Nov 2022 03:07:13 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0C792124E; Tue, 15 Nov 2022 00:07:12 -0800 (PST) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NBJg0745mzRpKx; Tue, 15 Nov 2022 16:06:52 +0800 (CST) Received: from huawei.com (10.67.174.191) by canpemm500009.china.huawei.com (7.192.105.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 15 Nov 2022 16:07:06 +0800 From: Li Hua To: , CC: , , , , Subject: [PATCH] watchdog: pcwd_usb: Fix attempting to access uninitialized memory Date: Tue, 15 Nov 2022 16:35:55 +0800 Message-ID: <20221115083555.22928-1-hucool.lihua@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.67.174.191] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500009.china.huawei.com (7.192.105.203) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749548949089688015?= X-GMAIL-MSGID: =?utf-8?q?1749548949089688015?= 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 --- 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;