From patchwork Wed Nov 11 09:06:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 11897007 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64DB8C4742C for ; Wed, 11 Nov 2020 09:08:50 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E20EF206F1 for ; Wed, 11 Nov 2020 09:08:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="iVCLJN8p"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="oU+aGEmh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E20EF206F1 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=microchip.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=bEqRQAaudutLEI0TOi8rQhTWuAS+Mw0EiRjgedCiOPA=; b=iVCLJN8pb4rmKpcyT/nMY4Wby OT5qyrRX5xu4VzOPbryJ+MQ03cUPvhDofZ7j9HPbRrBd7lXYew75ULZqyhUBK2ZiChLHIjzPcCpm5 +8TmDj52V4+v9/Bn8FtJLVG6io+u9up+XmC32tzfrP9HTe77DsXVQAwtuOnLd5ogBE0D8FHW52nHC 3mortmT0qcY9XKfaPj3feafj2fugA2ETR8GKde/wnFnwb54SGAVUsmKEy7o0GizTQTrdD85zRzXS3 Z3S31DSB+LgePdhSAw15rF4RFcHpg662iIeBEa6xpyeBqO8sYMDHK8x8jMwVMWk78Y/v97eXr/3eO yMkbyLGiA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcm6C-0003zM-0D; Wed, 11 Nov 2020 09:07:28 +0000 Received: from esa2.microchip.iphmx.com ([68.232.149.84]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcm65-0003xu-P3 for linux-arm-kernel@lists.infradead.org; Wed, 11 Nov 2020 09:07:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1605085641; x=1636621641; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=b/5OjSM9VK1XMAdLydktZ7tDE6fgDTRGJoBG4hNXffM=; b=oU+aGEmhU7EvniAkS48C9O8182gALjrRIJoMYUqWqlF/r2YQWN9IhUcL k4ucRfVyVWaAE7MkP/XdImE/P58ncThGIYDH61Rj2PrA4wQiFlfd7UH+Y h0mz4i+wuQR61WlGFHYo+jB1SoyXKRkKGAOmuicdxvMyMu3hJ3sXMvnOM PbCWHg1FF9AZzAD6PDfBVLVotX0L7Hczaf6gs2u7AfpLZkBQ5NhLddyUe cMya3q0mwZz2bRgl7rsnvkv5r9qnfM36mzVurUWAJiMcZkCcqFNYcPw8T FNPBep3FHmAQgrpyDTIQaGq5We9vgXaTrqX/8fxWEdIgynOf4Nw87Thec Q==; IronPort-SDR: 9Wyz7SN26vF/d7IlZ7Zw0pjy4XySquLGnIMG+Bwk5gR+abZGvWyeox14z7/TGN0GYEsOmyzmpg tUF3TpQt9VhBW+vs75quITI1hizqPm8m/XpKChcKGbie12ZSv56ELTN699jyW8q5SOvffS5tzV HzWsu35qGGyqSVtMb9scWpdIFZMm+MTlKYBqtF2XiDlcU6Diy/KmyCNHubCFjOPhfpoqwkPZhY eiwU44epRez2HG371A8nAtDNInFnazNIfxedRkGPTxWczJOy293bpkbfV7Ef6xGYZCiJ9yhklI wqU= X-IronPort-AV: E=Sophos;i="5.77,469,1596524400"; d="scan'208";a="95887102" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 11 Nov 2020 02:07:20 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 11 Nov 2020 02:07:20 -0700 Received: from m18063-ThinkPad-T460p.microchip.com (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.1979.3 via Frontend Transport; Wed, 11 Nov 2020 02:07:17 -0700 From: Claudiu Beznea To: , Subject: [PATCH v2 1/6] regulator: core: validate selector against linear_min_sel Date: Wed, 11 Nov 2020 11:06:13 +0200 Message-ID: <1605085578-6783-2-git-send-email-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1605085578-6783-1-git-send-email-claudiu.beznea@microchip.com> References: <1605085578-6783-1-git-send-email-claudiu.beznea@microchip.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201111_040721_961722_97414249 X-CRM114-Status: GOOD ( 13.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: axel.lin@ingics.com, s.hauer@pengutronix.de, linux-kernel@vger.kernel.org, Claudiu Beznea , ttynkkynen@nvidia.com, linus.walleij@linaro.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org There are regulators who's min selector is not zero. Selectors loops (looping b/w zero and regulator::desc::n_voltages) might throw errors because invalid selectors are used (lower than regulator::desc::linear_min_sel). For this situations validate selectors against regulator::desc::linear_min_sel. Fixes: 3a40cfc36bb3d ("regulator: core: create unlocked version of regulator_list_voltage") Fixes: 04eca28cde52c ("regulator: Add helpers for low-level register access") Fixes: 88cd222b259d6 ("regulator: provide consumer interface for fall/rise time") Fixes: d295f7670127e ("regulator: core: Move list_voltage_{linear,linear_range,table} to helpers.c") Signed-off-by: Claudiu Beznea --- drivers/regulator/core.c | 9 +++++++-- drivers/regulator/helpers.c | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 2e1ea18221ef..1d0d35f14f37 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2958,7 +2958,8 @@ static int _regulator_list_voltage(struct regulator_dev *rdev, return rdev->desc->fixed_uV; if (ops->list_voltage) { - if (selector >= rdev->desc->n_voltages) + if (selector >= rdev->desc->n_voltages || + selector < rdev->desc->linear_min_sel) return -EINVAL; if (lock) regulator_lock(rdev); @@ -3109,7 +3110,8 @@ int regulator_list_hardware_vsel(struct regulator *regulator, struct regulator_dev *rdev = regulator->rdev; const struct regulator_ops *ops = rdev->desc->ops; - if (selector >= rdev->desc->n_voltages) + if (selector >= rdev->desc->n_voltages || + selector < rdev->desc->linear_min_sel) return -EINVAL; if (ops->set_voltage_sel != regulator_set_voltage_sel_regmap) return -EOPNOTSUPP; @@ -4032,6 +4034,9 @@ int regulator_set_voltage_time(struct regulator *regulator, for (i = 0; i < rdev->desc->n_voltages; i++) { /* We only look for exact voltage matches here */ + if (i < rdev->desc->linear_min_sel) + continue; + voltage = regulator_list_voltage(regulator, i); if (voltage < 0) return -EINVAL; diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c index e4bb09bbd3fa..974f1a63993d 100644 --- a/drivers/regulator/helpers.c +++ b/drivers/regulator/helpers.c @@ -647,7 +647,8 @@ int regulator_list_voltage_table(struct regulator_dev *rdev, return -EINVAL; } - if (selector >= rdev->desc->n_voltages) + if (selector >= rdev->desc->n_voltages || + selector < rdev->desc->linear_min_sel) return -EINVAL; return rdev->desc->volt_table[selector];