From mboxrd@z Thu Jan 1 00:00:00 1970 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 4BA80C55ABD for ; Fri, 13 Nov 2020 15:22:56 +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 C3AE922249 for ; Fri, 13 Nov 2020 15:22:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="QhrRyI/6"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="MEwbNptm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C3AE922249 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=QhrRyI/6K5dIROe3TGQeigIfU EuK1GTHMsSGNujIqukHhcPRw8/ECQJlE10KgWWUvRNpuxn+Yfv/xEIM0A9ljls0qADTZBouGztmps HXAqxV3XHSj3ilVQTbXS7UtdCQH9oy+RkatY/PeYQsrlN8snL44YpZtJfzIq6IpQ6izsGnr2TWB/M WID5KsRU1vdcPT3lGqVEHxndFaT7NxwNSxbp/WeSJ4414g8pCVdBL5rmPbFN8avm6mnsmJRO7Tb0X F7n5hALWBGqaRYNjUJtJD74O2ZQyMDE15SnC7tclTyNi4zGe+CaAY30/ApJD9PAvLSAyLuAUgG44u 4YM6PCJVg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdatK-0001Sa-KU; Fri, 13 Nov 2020 15:21:35 +0000 Received: from esa5.microchip.iphmx.com ([216.71.150.166]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdat9-0001P1-Em for linux-arm-kernel@lists.infradead.org; Fri, 13 Nov 2020 15:21:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1605280884; x=1636816884; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=b/5OjSM9VK1XMAdLydktZ7tDE6fgDTRGJoBG4hNXffM=; b=MEwbNptmHBb7/pPqKFjQb9TihHzoLKEuHMagQ9dB91bs6HluFvFSM8UB QkfcjSh4R6mkQyHxAUN4JuX0l+r6dUyU7Dz2Pq8eRZpUJ0xTH1KRHgNC/ Hi4HTXHEN8LnKadYJKW6/1cabWvKuhmjX3VPGsod+g+UDYiWtSPV9unUZ 2ygRcl6TyVZ8XZ1FAfmxkP88Phn6V23MgSeAnavVwlhxj44bpAaK9Zm5Q GUs4qnHtAtDXj8/H830URgfUVXymfGZGv09Vtgry+nkLBsofYTlVejjcf hq1h1ua5OgqpESgjaQ4qh/5lLMPHb08tuE3NyjCWE0KN/jVbN1WImPxDi A==; IronPort-SDR: IwrEie/D51TUBqmvPqmLaMpbC6si7Uke5nKRz1buYHsojR8qFLQzUV8kDMhssuoqt23/VaYHFV x5Rv425AoOcCQhLGFr8RcOC1ed05TB04xxmKgTa2Fbl+hyPEdnOipcnnPm8NBvz4iA9w6ReX5v dod1ll6wRkx1HD6M7HCumP521I6xBx4ou2J8XwL8JMgmcKWZ/qa7biDCSbW8dAeUj5n4Bn8GIl qVHfrfVgKIrls2dmqzsrvV/zBAJEaMSXwAoLfa4hahckg+/calOIZ8n5OwNteMzrvxoy+cZgx8 tuc= X-IronPort-AV: E=Sophos;i="5.77,475,1596524400"; d="scan'208";a="98340440" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 13 Nov 2020 08:21:23 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Fri, 13 Nov 2020 08:21:22 -0700 Received: from m18063-ThinkPad-T460p.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.1979.3 via Frontend Transport; Fri, 13 Nov 2020 08:21:18 -0700 From: Claudiu Beznea To: , Subject: [PATCH v3 1/6] regulator: core: validate selector against linear_min_sel Date: Fri, 13 Nov 2020 17:21:05 +0200 Message-ID: <1605280870-32432-2-git-send-email-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1605280870-32432-1-git-send-email-claudiu.beznea@microchip.com> References: <1605280870-32432-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-20201113_102123_716626_0C070483 X-CRM114-Status: GOOD ( 13.79 ) 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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]; -- 2.7.4 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel