Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp658285rwb; Wed, 16 Nov 2022 06:07:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf5dXZeQRE94s3f/mcVVZKwXEKej9juWlqoTpg5M++c3qT80AuUjEYmESug6BuVQqWo1eynv X-Received: by 2002:a17:903:40d2:b0:186:7a1d:b6ee with SMTP id t18-20020a17090340d200b001867a1db6eemr9317471pld.67.1668607678560; Wed, 16 Nov 2022 06:07:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668607678; cv=none; d=google.com; s=arc-20160816; b=yPrQcyJqBq5xrIZcp/jVjacTYGb8i9dUiAJaZUeirTID00Gw0uZlFmQgajLjoaf1P2 z901SD8XMVePWJSSwRMSLpF1ejVvv9IY6bYM3HGOjTvEstMl3t7jeTNsLb+sJLG1PmM/ pmsCrBH9Z70+pmbBNN9bmGEqT5i/Qf0oEFCBY2WGZvY86eYQZyZAGc0JByMARjqswPpy dgleSUQi1iWuLCWe9BznY0KzgzAu2Om/ptSeRnJzNKSwt5YJbkg3Kzd4b2EcdnUwn2mz xPRu5d9npj/26bEGCuuKDhR6HgJj/APYsWbHzAv1hbBBSTEVzmw6c4AQUATkqGlzxSbz 4Iqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:sender:dkim-signature; bh=F2v0reJ03oQ3N+WnL3S2soD9eTu9KQZuxthHEtmAPEQ=; b=ZrIBo7mp/o/JRp1dnY0+iMnKWiEqoU0gsEWoAuJaqiYa6BrsHPEeygJLOe65F435RE 2OVYSit22tsj/8OoxzqAhihUACMPoyJ9+GzlyUyY+lkcSPjCGX9xvyvi91cjIJW/2xM1 oHaRSzoTzNCJYUwmuqhy91Vj6b/0VZmOpLS7xTGsjg3ho5hvh1c42Hq1z3t4ilHpj0Wd hKc8VQlRP+sCihlAQFZvQkRvrvWoJHLjuylB8fslbzhDqYm1ACZ7oXPN9kMhWSnBrgw8 4vgaHdP/5ZmAadLlK6U0XBhW2ON2Rqlt2meNK480DLXlaDuCKHR8h/xq03rEtvrHxMxs Eh3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jWenCqon; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m5-20020a17090a3f8500b00213353d1107si1794100pjc.172.2022.11.16.06.07.34; Wed, 16 Nov 2022 06:07:58 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jWenCqon; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233835AbiKPN6W (ORCPT + 91 others); Wed, 16 Nov 2022 08:58:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232788AbiKPN43 (ORCPT ); Wed, 16 Nov 2022 08:56:29 -0500 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AB4A450B7; Wed, 16 Nov 2022 05:52:59 -0800 (PST) Received: by mail-pl1-x62c.google.com with SMTP id p21so16473212plr.7; Wed, 16 Nov 2022 05:52:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:sender :from:to:cc:subject:date:message-id:reply-to; bh=F2v0reJ03oQ3N+WnL3S2soD9eTu9KQZuxthHEtmAPEQ=; b=jWenCqonb1DW2SKwL0/8E7iBjB4hzBEJdgxj5MtXETzo8amTO60Ocw0LxgCgf2OePX RhePBphEpAdXhadVe6QtpdsR2ZrQnBohklAy0oNFQzDgLaBCRvpsF3XRR1shadid64s5 Fd9oFfRI7AUgF+FBNNMxrMnoFr1CrncDnUCsOdPSdiytoMgiUBel+d1tGtPgIpH6RPPW WGPTJMXAYAO6xnRWaPvHIwAp4Z8O+cmANFxKq5yHJqfLTDy1LKGH7/J8WObHlMWLeQYU bDFrFGXrp4DrhSBdzl00dRWcQ8RsAeUE1Fmzv42bT8ljYR0dZhoTyUgorP9t6rA2+Gyw 0S2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:sender :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=F2v0reJ03oQ3N+WnL3S2soD9eTu9KQZuxthHEtmAPEQ=; b=UpriC3MbS8fZLOkcPnJTMp757w4l6DyvjJp93JeceW075j8UYvluZXlXtVmGfXOpIq qoNEBmmQZGY+F9LivheCxTnx74RH1oLzqG2XIT/NbGYh1PvIwNueaWSJRmx5hCp/I8Jv ey8smqOQ91cSTBg8+02D0pmNLRkHdksKTvJCrpmaYYhsqcTGSeoxigLDye97wEQpfWK0 iYFLI7b+5wMROZwDmUJvMuFW7SGyCnLNkMnFPeecSmqAu+fNy/IjyGYsHFTxkMX9FdVW cCZxw4kUBNZMTQrqLbeKF9UCc68Z8IkwK0MXIozmqh5LlwpZSKtE4qhUHveejoRI92OT uHrg== X-Gm-Message-State: ANoB5pkDBW2CDmLO95ndMDbZNEO1ire+KUtWs8FyCbD/hmiPR8vaxt0b olXB6zZWqMT1JL5xunAV6gkohrFFicc= X-Received: by 2002:a17:902:f787:b0:186:971b:b7e5 with SMTP id q7-20020a170902f78700b00186971bb7e5mr9379282pln.54.1668606778974; Wed, 16 Nov 2022 05:52:58 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id b4-20020a170902d50400b00186ad73e2d5sm12351879plg.208.2022.11.16.05.52.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Nov 2022 05:52:58 -0800 (PST) Sender: Guenter Roeck Date: Wed, 16 Nov 2022 05:52:57 -0800 From: Guenter Roeck To: Li Hua Cc: wim@linux-watchdog.org, linux-kernel@vger.kernel.org, linux-watchdog@vger.kernel.org, weiyongjun1@huawei.com, yusongping@huawei.com Subject: Re: [PATCH v2] watchdog: pcwd_usb: Fix attempting to access uninitialized memory Message-ID: <20221116135257.GB3498904@roeck-us.net> References: <20221115134213.GD4189373@roeck-us.net> <20221116020706.70847-1-hucool.lihua@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20221116020706.70847-1-hucool.lihua@huawei.com> X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=no 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 On Wed, Nov 16, 2022 at 10:07:06AM +0800, Li Hua wrote: > 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 */ > -- > 2.17.1 >