Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3705612imj; Tue, 12 Feb 2019 03:20:07 -0800 (PST) X-Google-Smtp-Source: AHgI3IZUV3oYJdERYjZIYCc6usecw4J3JPwwd7ha6alqCmdBlDpNxZWiXZozJwwLF2nf8LgaPd0L X-Received: by 2002:a17:902:e287:: with SMTP id cf7mr3574592plb.51.1549970407552; Tue, 12 Feb 2019 03:20:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549970407; cv=none; d=google.com; s=arc-20160816; b=RRBGEkVyjzQ++yYBlaANwpTET3TuqINg8Vo3sASAbscOtaAQZdjOUwEhXJCouxPoy+ 0p1PppJakKxCt6t2m45fn73/dV3/JehXZt6Rn6JNbjZSpHqHhnEKf2ob+rM+jzYIeCK2 6494A8/vWMtKMJEbmHplSLzJp4BlTg6fybM2LdUY4n3KApUSeyXbszCZCgeI0UVmFkMk TxcisSCzw6DwMrgM9qdCvx4Y29hDesbJnRBjdQlseXRcoSO1vqsA5jutUexbkUOzp4Qf rcB5Y2UuTM/Q7AypsYKwQulfiC9MzSSzS1eSFy/R9RZffhlXzaRRz4AE6MTkJpJkLOwR Ip8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=0z3k4oJqzqvFOCSbhMlgECjcktfrU22zGBqphO0acYw=; b=jbQNkts9gsUVE9hOE/a4a7rMj6OIjfy+CCUw5iBq1L8Q7PiXvuZPw39XV69zRUWuwR 2LApJfVJo1bPLf5NYhcul5kK5vAXHOl8fstGTA+fwGuqNdGUONI97LsvpUmLgPBZkLYq glp6wik0iAw5OELnG8xdamx49UY0Mop+eCF3gluX0RToQc9Lo6Gje0Ceo2y0D9j/Gpf4 EaYzsp41RpghgsLDLp+0SvnKmPwKnC+Ni7cZFUBhjZR6wnzJrB/4IR1CyDZD+fkqviP4 84exKmZqlN02jiG8f73slz1jKTwOIDq8H6orTiRq+hmQxmDhJjO1w9KyL063WZF8DB49 tuBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v10si13092564plp.424.2019.02.12.03.19.51; Tue, 12 Feb 2019 03:20:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728951AbfBLKrn (ORCPT + 99 others); Tue, 12 Feb 2019 05:47:43 -0500 Received: from gloria.sntech.de ([185.11.138.130]:35280 "EHLO gloria.sntech.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728184AbfBLKrl (ORCPT ); Tue, 12 Feb 2019 05:47:41 -0500 Received: from ip5f5a6320.dynamic.kabel-deutschland.de ([95.90.99.32] helo=diego.localnet) by gloria.sntech.de with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gtVbA-00013l-F1; Tue, 12 Feb 2019 11:47:32 +0100 From: Heiko =?ISO-8859-1?Q?St=FCbner?= To: Yizhuo Cc: csong@cs.ucr.edu, zhiyunq@cs.ucr.edu, Kishon Vijay Abraham I , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org Subject: Re: [PATCH] phy: Variable "caldone" in function rockchip_emmc_phy_power() could be uninitialized Date: Tue, 12 Feb 2019 11:47:31 +0100 Message-ID: <1884796.YtlDmFZGdE@diego> In-Reply-To: <20190206014733.21094-1-yzhai003@ucr.edu> References: <20190206014733.21094-1-yzhai003@ucr.edu> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am Mittwoch, 6. Februar 2019, 02:47:33 CET schrieb Yizhuo: > In function rockchip_emmc_phy_power(), local variable "caldone" > could be uninitialized if function regmap_read() returns -EINVAL. > However, it will be used directly in the later context, which > is potentially unsafe. > > Signed-off-by: Yizhuo > --- > drivers/phy/rockchip/phy-rockchip-emmc.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/drivers/phy/rockchip/phy-rockchip-emmc.c > b/drivers/phy/rockchip/phy-rockchip-emmc.c index f1b24f18e9b2..ca921ae08309 > 100644 > --- a/drivers/phy/rockchip/phy-rockchip-emmc.c > +++ b/drivers/phy/rockchip/phy-rockchip-emmc.c > @@ -85,11 +85,12 @@ struct rockchip_emmc_phy { > static int rockchip_emmc_phy_power(struct phy *phy, bool on_off) > { > struct rockchip_emmc_phy *rk_phy = phy_get_drvdata(phy); > - unsigned int caldone; > + unsigned int caldone = 0; hmm, this may hide actual uninitialized uses in the future? With the added error handling below, there shouldn't be a case where caldone might be used uninitialized still? Heiko > unsigned int dllrdy; > unsigned int freqsel = PHYCTRL_FREQSEL_200M; > unsigned long rate; > unsigned long timeout; > + int err; > > /* > * Keep phyctrl_pdb and phyctrl_endll low to allow > @@ -164,9 +165,14 @@ static int rockchip_emmc_phy_power(struct phy *phy, > bool on_off) * wait 5us for calpad busy trimming > */ > udelay(5); > - regmap_read(rk_phy->reg_base, > + err = regmap_read(rk_phy->reg_base, > rk_phy->reg_offset + GRF_EMMCPHY_STATUS, > &caldone); > + if (err) { > + pr_err("Failed to read status.\n"); > + return err; > + } > + > caldone = (caldone >> PHYCTRL_CALDONE_SHIFT) & PHYCTRL_CALDONE_MASK; > if (caldone != PHYCTRL_CALDONE_DONE) { > pr_err("rockchip_emmc_phy_power: caldone timeout.\n");