Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17939997ybl; Thu, 2 Jan 2020 15:12:54 -0800 (PST) X-Google-Smtp-Source: APXvYqwDMBfvlTQwK8849VV7/FeY1oEOAZhUaRv5mlCWdbBpV7n+F7Z7uxC8govxJgL4gIRkP2vt X-Received: by 2002:a05:6830:1487:: with SMTP id s7mr70910003otq.269.1578006773978; Thu, 02 Jan 2020 15:12:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578006773; cv=none; d=google.com; s=arc-20160816; b=Z0aqCxP3+C+Iejfa+lb+88QKjk23DQ7WjDspFQO/VacWWyk22WVKxpHPtmoVLrz91g nHebMdnOb7icyH60+Mv0BglQYfBcwNu/Pcv83WlbEUo+NH/hLMuH3iw1Zu5Ezt92+ikY 4bP5R0N1bD6CAkq2vLwi4fYmjeLjV8E9WjoWVn/EUN0uoU3QHs3+T5rROrJNWAyZU0I1 6bzJpB1u5SnEm/WDCKB8G8vrUWCRlT3eugS62IhP1rD9sS9QBwTEYNRlKwTu+6C6fS/B CUTGX+kxMkPjC4lo0SSSAx+2Vp2ECsorCYbH/1Uaq/1u7chWJF5Ar9fUPzYfwYknYSxR QRBA== 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=MNXp6j4U4pV2E6fLuLx+i/3+A1nkgCwOegAfLa2evvw=; b=T0SEc01oNxJoN7N0L02lhiX/Xbi7TMoQUkJ70azO606NbMcbfyUwyRUlFudrhG4+2c z92Pi/aX3kRk/nj89CsRY54odX+sfOcryO+Iy9IY10nrk6/jAfoQGkhSXH8cAmlZLCJm ZGZKHdVGWqfNlfT68MnqK8i9MNUIEpTqlIjrCEP9AMSnOt2rT+Uj2HXmz/9TIqRbPN3E 9ciZMXHsJdz3PAkGJRJgCbUdhFwoReXHUpQCmaWYmpP5edtlqLjd5e1Id348g6EAkV0G g1idk9FIb0qhfxfFLrilQDek0AASY3GmQNscweYzs2ZDcN66ZunAuNhv5nrLjURl0CJx AgtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qGOuBZZl; 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 17si12557235oix.22.2020.01.02.15.12.42; Thu, 02 Jan 2020 15:12:53 -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=qGOuBZZl; 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 S1729621AbgABWno (ORCPT + 99 others); Thu, 2 Jan 2020 17:43:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:42912 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728341AbgABWeY (ORCPT ); Thu, 2 Jan 2020 17:34:24 -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 1FD3320866; Thu, 2 Jan 2020 22:34:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578004463; bh=Y6oTPyUWl/LYXYiiXw8VnlrTivTKYu9uWlex9b/y5nM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qGOuBZZla0WedbfUfZ+Qi0VwrLRnJHxu9NBqze0R63sFWAA191nLaoBAN7/pR5x3T hl5QQFGTDj3Sgy3hrpIOT2lR4sASWwF4F9Q/JtlxftyNj+XL0iceq/xiR8N8qZ2sVU MSP3tiAEBVm2/GlDWahhZt2Xo4MmlUQuyV9iV56k= 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 4.4 018/137] regulator: max8907: Fix the usage of uninitialized variable in max8907_regulator_probe() Date: Thu, 2 Jan 2020 23:06:31 +0100 Message-Id: <20200102220549.118412336@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220546.618583146@linuxfoundation.org> References: <20200102220546.618583146@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 5e941db5ccaf..c7e70cfb581f 100644 --- a/drivers/regulator/max8907-regulator.c +++ b/drivers/regulator/max8907-regulator.c @@ -299,7 +299,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; @@ -336,14 +339,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