From patchwork Sun Jun 22 15:31:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beniamino Galvani X-Patchwork-Id: 4396201 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3F4619F79B for ; Sun, 22 Jun 2014 15:37:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7A4892021B for ; Sun, 22 Jun 2014 15:37:39 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8E8B92024F for ; Sun, 22 Jun 2014 15:37:38 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WyjmB-0005rN-4x; Sun, 22 Jun 2014 15:33:51 +0000 Received: from mail-we0-x22d.google.com ([2a00:1450:400c:c03::22d]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wyjm3-0005nU-OC for linux-arm-kernel@lists.infradead.org; Sun, 22 Jun 2014 15:33:44 +0000 Received: by mail-we0-f173.google.com with SMTP id t60so5797285wes.32 for ; Sun, 22 Jun 2014 08:33:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bhIDfcHdDximNRGuR5ZhBwBqAwUizefscovXs1pw1t0=; b=eTgq8WlaY/PadN3uoywE80DK9lrIS2kgxLT6buPmZJhQSktavGu81RAy2IStQHrXwl iF3W+MxJYwYSbf+5pxYP3+dE3SLMmNpn9gvu9p3sjPEW4778XumbZwAcBfS/JaeAOsQA 4dPpC9/spSv3Svk4G5lLQk+565GrPhjswD07DImMSl4BipBotDE3tvGw2mI3OClmAcdu JGC4f19CosM2f7T7zyR8OmX8o+QfBVCZxu/GAQImXLAohFh8nigx9IDKKdLb3elAI9GD RkU9911GG24S1DodbAcZinw+7FHipQq2nJ13S/4TnFNT5hUuLs1QJl7rygg9QegJwlBr b3DQ== X-Received: by 10.194.22.100 with SMTP id c4mr20422413wjf.89.1403451200895; Sun, 22 Jun 2014 08:33:20 -0700 (PDT) Received: from sark.local (host188-27-dynamic.31-79-r.retail.telecomitalia.it. [79.31.27.188]) by mx.google.com with ESMTPSA id ex4sm24500007wic.2.2014.06.22.08.33.18 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 22 Jun 2014 08:33:20 -0700 (PDT) From: Beniamino Galvani To: Liam Girdwood , Mark Brown Subject: [PATCH 1/5] regulator: act8865: fix parsing of platform data Date: Sun, 22 Jun 2014 17:31:41 +0200 Message-Id: <1403451105-31929-2-git-send-email-b.galvani@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1403451105-31929-1-git-send-email-b.galvani@gmail.com> References: <1403451105-31929-1-git-send-email-b.galvani@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140622_083343_939997_78DE7A8D X-CRM114-Status: GOOD ( 16.34 ) X-Spam-Score: -0.8 (/) Cc: Mark Rutland , devicetree@vger.kernel.org, Heiko Stuebner , Pawel Moll , Ian Campbell , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Wenyou Yang , Beniamino Galvani , Rob Herring , Kumar Gala , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The driver loops through all available regulators (ACT8865_REG_NUM) and accesses pdata->regulators[i].platform_data without checking the actual value of num_regulators in platform data, potentially causing a invalid memory access. Fix this and look up the regulator init_data by id in platform data. Signed-off-by: Beniamino Galvani --- drivers/regulator/act8865-regulator.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/regulator/act8865-regulator.c b/drivers/regulator/act8865-regulator.c index b92d7dd..fe2c038 100644 --- a/drivers/regulator/act8865-regulator.c +++ b/drivers/regulator/act8865-regulator.c @@ -252,6 +252,22 @@ static inline int act8865_pdata_from_dt(struct device *dev, } #endif +static struct regulator_init_data +*act8865_get_init_data(int id, struct act8865_platform_data *pdata) +{ + int i; + + if (!pdata) + return NULL; + + for (i = 0; i < pdata->num_regulators; i++) { + if (pdata->regulators[i].id == id) + return pdata->regulators[i].platform_data; + } + + return NULL; +} + static int act8865_pmic_probe(struct i2c_client *client, const struct i2c_device_id *i2c_id) { @@ -261,7 +277,7 @@ static int act8865_pmic_probe(struct i2c_client *client, struct regulator_config config = { }; struct act8865 *act8865; struct device_node *of_node[ACT8865_REG_NUM]; - int i, id; + int i; int ret = -EINVAL; int error; @@ -299,20 +315,17 @@ static int act8865_pmic_probe(struct i2c_client *client, /* Finally register devices */ for (i = 0; i < ACT8865_REG_NUM; i++) { - - id = pdata->regulators[i].id; + const struct regulator_desc *desc = &act8865_reg[i]; config.dev = dev; - config.init_data = pdata->regulators[i].platform_data; + config.init_data = act8865_get_init_data(desc->id, pdata); config.of_node = of_node[i]; config.driver_data = act8865; config.regmap = act8865->regmap; - rdev = devm_regulator_register(&client->dev, &act8865_reg[i], - &config); + rdev = devm_regulator_register(&client->dev, desc, &config); if (IS_ERR(rdev)) { - dev_err(dev, "failed to register %s\n", - act8865_reg[id].name); + dev_err(dev, "failed to register %s\n", desc->name); return PTR_ERR(rdev); } }