From patchwork Wed Nov 16 02:07:06 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: 20654 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3040401wru; Tue, 15 Nov 2022 17:45:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf5rvdrjSp5gQG2TOK1pC6DF95hemAd0bU5WbPii+QSmWEJsjPQCB+cMPsA/UyV3dYN3hiA7 X-Received: by 2002:a17:907:36c:b0:78d:3341:aa8 with SMTP id rs12-20020a170907036c00b0078d33410aa8mr15504973ejb.96.1668563121121; Tue, 15 Nov 2022 17:45:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668563121; cv=none; d=google.com; s=arc-20160816; b=EgYeFYytdNtEL2MKdAoSoyFRmnyPHcqOLBWbRyCKhTYK3NJpb9d9/c3cLjCy56Wgh6 PqylU5ZiR5oA5UEERIfrtIutJnDkjlSZyyGAV/0ZwIanI+MU7y7I6q06OtUdz5epJ3yT XNG4GwVdY5nJ3lXlld6tHLOtMETX3gj28muvAwFq3mxPqP75Jzk2hzUiiz5jhMaPF9xA mQDBTED7ycX1TRrVUYpracCp2kM/d6laTpBslL8BFrZXY5b1jCtRxhS49LNVxje8EuhB bgwuV0Tw71gOmvJCpoQR2xwTtFitrUb+GXQEHhS40zHy1J9N5D0PBqxRWRI71dLU/1Wl SgSA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=W0VJUUQ0g8y7ekYqTNOhSi6j3ukhDjt0nZjaXMybPWU=; b=irN5GL+TLhdCaaeq5lCoVRLwZtd7JDFeIDcbsWKNuNFWiUfm6qPDhemzov9X8pYNOP stWOmCxgtF2x+HQoTxJNyMZdPHRqhSS89ozA3MZd4rLuJ0To7JcbtGMZpe86uMk94p+8 z36HyZyFvE1ioclaEDMeTNqGGseCkRMChPVJs3YfDwkThWycFCWpOYw6usr117DcSQS0 n3rxrN5qU92yiIzRAOJMz+wr87taOoozDicWMXjXWY1/97aTVCRqU8QjzlcM+L1cDNJ3 aeqDJkZiS/ODboSXHuabV6WbZf6gg31jFqVxUg1rd6koqwu5iyNrYGdkZGH4NH/zqymg rhwA== 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 f16-20020a17090631d000b007ad86f97b36si9761936ejf.560.2022.11.15.17.44.57; Tue, 15 Nov 2022 17:45:21 -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 S231216AbiKPBia (ORCPT + 99 others); Tue, 15 Nov 2022 20:38:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229561AbiKPBiY (ORCPT ); Tue, 15 Nov 2022 20:38:24 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EB942AC; Tue, 15 Nov 2022 17:38:23 -0800 (PST) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NBlzr50s2z15MPB; Wed, 16 Nov 2022 09:38:00 +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; Wed, 16 Nov 2022 09:38:21 +0800 From: Li Hua To: , CC: , , , , Subject: [PATCH v2] watchdog: pcwd_usb: Fix attempting to access uninitialized memory Date: Wed, 16 Nov 2022 10:07:06 +0800 Message-ID: <20221116020706.70847-1-hucool.lihua@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221115134213.GD4189373@roeck-us.net> References: <20221115134213.GD4189373@roeck-us.net> MIME-Version: 1.0 X-Originating-IP: [10.67.174.191] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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?1749615243039698727?= 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 Reviewed-by: Guenter Roeck --- v1 -> v2: just initialize lsb and msb with 0, but returning -EFAULT --- drivers/watchdog/pcwd_usb.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/watchdog/pcwd_usb.c b/drivers/watchdog/pcwd_usb.c index 1bdaf17c1d38..8202f0a6b093 100644 --- a/drivers/watchdog/pcwd_usb.c +++ b/drivers/watchdog/pcwd_usb.c @@ -325,7 +325,8 @@ static int usb_pcwd_set_heartbeat(struct usb_pcwd_private *usb_pcwd, int t) static int usb_pcwd_get_temperature(struct usb_pcwd_private *usb_pcwd, int *temperature) { - unsigned char msb, lsb; + unsigned char msb = 0x00; + unsigned char lsb = 0x00; usb_pcwd_send_command(usb_pcwd, CMD_READ_TEMP, &msb, &lsb); @@ -341,7 +342,8 @@ static int usb_pcwd_get_temperature(struct usb_pcwd_private *usb_pcwd, static int usb_pcwd_get_timeleft(struct usb_pcwd_private *usb_pcwd, int *time_left) { - unsigned char msb, lsb; + unsigned char msb = 0x00; + unsigned char lsb = 0x00; /* Read the time that's left before rebooting */ /* Note: if the board is not yet armed then we will read 0xFFFF */