Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6971341rwb; Tue, 15 Nov 2022 06:09:57 -0800 (PST) X-Google-Smtp-Source: AA0mqf4/TUb3zDs7G6/VAxynEtnhKCryc0P6ouSvb8PEORsc3hCnCzI4YvG4U4gehr2IONPiLUxx X-Received: by 2002:a17:902:aa4c:b0:188:9ae7:bb81 with SMTP id c12-20020a170902aa4c00b001889ae7bb81mr4273753plr.66.1668521397065; Tue, 15 Nov 2022 06:09:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668521397; cv=none; d=google.com; s=arc-20160816; b=daM3gACV/5MMxnevq2AlV8GwUpM2pRcFEigJE9ky/74BOB+1yvi+QcpIFZ2epMLjkK VCyHebYXrGsly1UGVwDw1Guc7t4GpUFWYo2/AMY2yr8pWmTSDuzMTsbE9DLiIr6OTep+ i3MqdVLjZGgtb2qE6WR+BdBmCTZo3UzPGx8vz0slIKg03/TGGsPRd0yyNEWVRLqUfITb 9OL9i3zUhqlxnKrzqCmWxJP1BJAFTh3YDICJ3ayBp/XJ7nhJmKkFva0x163GCKyrvOad 3M5DcDwN+4ibn0v3TezNIXlVfEY0BllD9uJ/7DBACp4yYjoM7mJH91oeDZUW2LFE/Gle G2/A== 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=Q24KX2057pThKailHphOfjZ+3umm1xp/JerUuUNakT4=; b=FJmE+Ex5no3OdUVfZeBc3TreYwwSD64BHsBGOKM1Pf85Z+AH0GnzZLlYdZSty48dqE iYCd1SObFJ0SBRsgDqw+FDWWmEbZMBxLiyiBML354R5hMvVaEya70ucUg04HzQ8TZH+J WQZ75by61gkFUcbmeHZuKVn6AnUY8d7KYZQA04S701XNLX34RersJG61hx6aaqHpWmUm xIxSwexNlLBazHeIhXpo9JKNoEvTEdQqTuE3jNNzr73eXp0mSeESOqcHXH0atRYnJU0g AD7CvwtWabThS/mPQw6/y1yG1EMSpZ+b936jsdE4TZ3PtvWhftpHSwn0ck6qtaJhfqOh YEGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=H6qyXXfu; 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 y14-20020a17090abd0e00b00210d1aeabc1si15522861pjr.188.2022.11.15.06.09.42; Tue, 15 Nov 2022 06:09:57 -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=H6qyXXfu; 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 S238293AbiKONmT (ORCPT + 89 others); Tue, 15 Nov 2022 08:42:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229747AbiKONmQ (ORCPT ); Tue, 15 Nov 2022 08:42:16 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 039A813FA6; Tue, 15 Nov 2022 05:42:16 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id q1-20020a17090a750100b002139ec1e999so13855805pjk.1; Tue, 15 Nov 2022 05:42:15 -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=Q24KX2057pThKailHphOfjZ+3umm1xp/JerUuUNakT4=; b=H6qyXXfuORPButKx1DlsOyhRzLlNHomtiA2jsmTdIkaeHKMm5NTaL5ppqj73pRf95K CmvBO6D+aHpO9xQ/nDntRFyOmmaeoGwnPIrvPnkGVlvOMADW8c5NkY2QL3aZKUf8MTl4 wSjzeB38FnMMf0goyKzdka9uQLLuZoggC6dupkPOAkl09pHpKjeguQhHEWJ1xr/NYcOC bi9o1NFty7WsAUm7xjw+B6h/mgw47w5aV6Zn4HpYyQIhBnO5qILWlGFxO7jIL4DJsrAp wI514g5uaiprB0fVhC8bULN96X/0jbgExQUzyXc8F2i86G/OTArwRs7VWcfAjHB16RrY DjiA== 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=Q24KX2057pThKailHphOfjZ+3umm1xp/JerUuUNakT4=; b=yqEjYmOc4PV3ylDycWnID1eUoZwKs68Gti+4nrxgZBgkSh+kdMy6GqkT9DNUTGK7bd Wo4mSqGYULtaz+0nSzU1xE7Ky4idi1YYM3mdyIanhEWYHv9sKr/MKS1L/ybDxi5JmCMA /zb6vAtUAFJnPTCN09328t8iocVEsEjMb0u7i+n7krYWBDtr1MmSSWiPDcWlCDlkHfTb hfweevtYi7FBxq63yTp+GEhpj19oCdfyJz1Dosv7Gy9oGx2Djbx3kwYyBbrd2+++PiAn 6jpoyNNEX8L1wqwTscCojGRxv+YlZrH1CLXGHMKV0JhYd+HkavfL6Fp+sgvNgBdTWSbx Pe5Q== X-Gm-Message-State: ANoB5pnxlCOrkvAO95s0xjQS+NuPDryXeCUprrNsGInvRWqILqvfkuIw ltikE3SrAiundpEMwVKHkcCPbICuciM= X-Received: by 2002:a17:902:f803:b0:188:602b:8259 with SMTP id ix3-20020a170902f80300b00188602b8259mr4044393plb.139.1668519735440; Tue, 15 Nov 2022 05:42:15 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id p4-20020a170902e74400b00186b55e3cd6sm9954797plf.133.2022.11.15.05.42.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Nov 2022 05:42:14 -0800 (PST) Sender: Guenter Roeck Date: Tue, 15 Nov 2022 05:42:13 -0800 From: Guenter Roeck To: Li Hua Cc: wim@linux-watchdog.org, linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, weiyongjun1@huawei.com, yusongping@huawei.com Subject: Re: [PATCH] watchdog: pcwd_usb: Fix attempting to access uninitialized memory Message-ID: <20221115134213.GD4189373@roeck-us.net> References: <20221115083555.22928-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: <20221115083555.22928-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 Tue, Nov 15, 2022 at 04:35:55PM +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 > --- > 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; > + } That all isn't really worth the trouble. If anyone still has the hardware, the driver should be converted to use the watchdog subsystem and to return useful error codes where appropriate. For example, returning -EFAULT as response to errors from WDIOC_GETTIMELEFT or WDIOC_GETTEMP is just wrong. If you really want to do anything, just initialize lsb and msb with 0. Guenter