Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp13473728ybl; Sun, 29 Dec 2019 12:46:03 -0800 (PST) X-Google-Smtp-Source: APXvYqx9gginHtPMxFk5LaEsTaP1WBetpnHufmut8Cds+2znLOnTshJZ8/05yghGUXqyi6x0A+sP X-Received: by 2002:a05:6830:184:: with SMTP id q4mr53177904ota.232.1577652363600; Sun, 29 Dec 2019 12:46:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577652363; cv=none; d=google.com; s=arc-20160816; b=JxLbEgad0//+jaeePdxa0x3g++T6/rB5CChvYeG54k3lz01UCPzDeApoyZySNmmznt fnf7CoSlIj2QjLVrIWY3TLmCbs7jKeNXHFLkaAlLt29SaX8DcCFl99qKJheQLJI6Byc9 oLYGa3S9K4bG1qdixRdXqa2oyt5EVJ8u+w3Dy96p3HIZO4Zh2U3H7bb5KF5sm27eNADW 5+3SQhsYBf03vAhu/NrJX0xV6yUefOBBd3vtBpd0qfcEiVENbjN3fbxW7+hpcv0CA59l DaK1plGku2wg6QgmtLxSGmts60WJCky6VhMDUGRYQFaqOENrpiANyOWDiFJYrccztXBJ AgIg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=do2vnMg8h5Wey0s6FyYKJglQ51ti9DVWsPGbeurqyS4=; b=Dk49x2JnFoYbv6ApLmCUBthEhxhOgKnqbLJonl6P1SAFmrnE6G4zmackijg+cjt3IR fbyYIuE5i5sfxoBbl/pG5t4UzEzQ+0sOeWEdyZEy0R11kR3K8wV47Y+iRpu/Z/5yaECj I9m2IeTtXfP9BEfflGW/lKcx6Ab/CNfkTduY0HkOWFXEVz9j8n/upZQjbdYPUmXb3SlB 6CxLtbskwwQdKhZhbQHTb5xI4aOeKSKG8fmrphURZeOj2W2Dc3ePb7hAEOcT+Z4HN99B DknzD3ehBGXMUmOJYLvuT69m48zHr5mT9DxxJxH2J4IlBCdVSvEEwa1eKqSo12R9pecT IPgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ALACHXSu; 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 c7si20629440otr.308.2019.12.29.12.45.53; Sun, 29 Dec 2019 12:46:03 -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; dkim=pass header.i=@kernel.org header.s=default header.b=ALACHXSu; 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 S1731133AbfL2Rqr (ORCPT + 99 others); Sun, 29 Dec 2019 12:46:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:56492 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731105AbfL2Rqg (ORCPT ); Sun, 29 Dec 2019 12:46:36 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6CAEC20718; Sun, 29 Dec 2019 17:46:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577641595; bh=vT/i1m2Czml8juZm5CYiD+AUEueXnzfNcVpXVGiBCyY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ALACHXSuZeh1HMXeOVHocF5Q1kXs5YUixomJDktEKcnOnvegNongONQ18gwSvxKU6 sbAqieVugnvBdAvcZ7nqwGmmayJS6x0eut40Fyq7q6OgiryWNfoCtUv2/PqKwUkt2m tzxU3u1B1FMk+0J/Z+u1edJMJVBei8Rzls0kJX1M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yizhuo , Mark Brown , Sasha Levin Subject: [PATCH 5.4 104/434] regulator: max8907: Fix the usage of uninitialized variable in max8907_regulator_probe() Date: Sun, 29 Dec 2019 18:22:37 +0100 Message-Id: <20191229172708.516185193@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229172702.393141737@linuxfoundation.org> References: <20191229172702.393141737@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yizhuo [ Upstream commit 472b39c3d1bba0616eb0e9a8fa3ad0f56927c7d7 ] Inside function max8907_regulator_probe(), variable val could be uninitialized if regmap_read() fails. However, val is used later in the if statement to decide the content written to "pmic", which is potentially unsafe. Signed-off-by: Yizhuo Link: https://lore.kernel.org/r/20191003175813.16415-1-yzhai003@ucr.edu Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/regulator/max8907-regulator.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/regulator/max8907-regulator.c b/drivers/regulator/max8907-regulator.c index 76152aaa330b..96dc0eea7659 100644 --- a/drivers/regulator/max8907-regulator.c +++ b/drivers/regulator/max8907-regulator.c @@ -296,7 +296,10 @@ static int max8907_regulator_probe(struct platform_device *pdev) memcpy(pmic->desc, max8907_regulators, sizeof(pmic->desc)); /* Backwards compatibility with MAX8907B; SD1 uses different voltages */ - regmap_read(max8907->regmap_gen, MAX8907_REG_II2RR, &val); + ret = regmap_read(max8907->regmap_gen, MAX8907_REG_II2RR, &val); + if (ret) + return ret; + if ((val & MAX8907_II2RR_VERSION_MASK) == MAX8907_II2RR_VERSION_REV_B) { pmic->desc[MAX8907_SD1].min_uV = 637500; @@ -333,14 +336,20 @@ static int max8907_regulator_probe(struct platform_device *pdev) } if (pmic->desc[i].ops == &max8907_ldo_ops) { - regmap_read(config.regmap, pmic->desc[i].enable_reg, + ret = regmap_read(config.regmap, pmic->desc[i].enable_reg, &val); + if (ret) + return ret; + if ((val & MAX8907_MASK_LDO_SEQ) != MAX8907_MASK_LDO_SEQ) pmic->desc[i].ops = &max8907_ldo_hwctl_ops; } else if (pmic->desc[i].ops == &max8907_out5v_ops) { - regmap_read(config.regmap, pmic->desc[i].enable_reg, + ret = regmap_read(config.regmap, pmic->desc[i].enable_reg, &val); + if (ret) + return ret; + if ((val & (MAX8907_MASK_OUT5V_VINEN | MAX8907_MASK_OUT5V_ENSRC)) != MAX8907_MASK_OUT5V_ENSRC) -- 2.20.1