From patchwork Fri Nov 6 09:52:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 11886683 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 F03E9C2D0A3 for ; Fri, 6 Nov 2020 09:55:48 +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 5F64A20B80 for ; Fri, 6 Nov 2020 09:55:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="zdkcpCIF"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Vt4gu8H+"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="J/WtlhCI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5F64A20B80 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=t5xf9Yu9rOJksOHl3KlVDnxfJFuh+ywRPgztNYbnNtM=; b=zdkcpCIFkIaeZBKL8ppF6bqJb S+E0r67cEip9gnxOegTgHE/ANUub/MwMkvaFRN1G3Xbwo2Cu6vVo/GQjQ+0Raibgln6l5dGUXOdts e0fV1C2wR/ZVRZgETgkmBOTrHCmEUUIuzdO+3m5y6BalGQKlQiko6/JFPOW22IjNbMmc1+lZOGzf8 ZC/Lxv3jyVZK/q7G4IcY51eYA0RGL8+AXynBxoiliAMDcAqAwrTqZoTiH1/SBeWTwTChVqoglOrjK trnWo9ZB2Ey+SkWAq3hQE9nM2kJDs4D3x+QVVBvw96wYL3hgI+qskctid7mvh+y/Ya9aZ/EvSJxRi vzOOLz/9g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaySa-0001YG-4v; Fri, 06 Nov 2020 09:55:08 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kayR3-0000vT-KN for linux-arm-kernel@merlin.infradead.org; Fri, 06 Nov 2020 09:53:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=jZhpnPninqzCH7mIVWb/0nqGM1gn56NLueF/t1O1c3U=; b=Vt4gu8H+Q17EXHdLikIB2wKo3p +fEPlQCvRMuSLbK1YI6cdZDCSuVkyV5glnZHYMsEzBrX167zqn5gDj8X+Xgh4xrYfNnQv7+fU6x17 WAn3iA7z9fv7saorXy6+8MbwnkvzNROHInaSxvm92R5Bt1g9rKld44IqaV+ay5M5N+4spyffgLwg8 +iXEUTsYwy2XnxcuFuZyu+ZSFmo7/QoeGtFLcDRvmRMkvwEjml1Ex0E9S/cxZq0RaB23bG7iC8V+y +JEZdFQ1YmPrdcrNajpxYQrduWFycN08WDI8ES8zVphMGuLOv+ibJXMaLLSwBRo5hnrZi/cCqOZWR 2M1dgHzQ==; Received: from esa4.microchip.iphmx.com ([68.232.154.123]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kayQy-0006K7-LE for linux-arm-kernel@lists.infradead.org; Fri, 06 Nov 2020 09:53:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1604656408; x=1636192408; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=mejcBh7mSpK+NaRWBuBUxvtD3CQQT8ZFwmAoxp9GPBM=; b=J/WtlhCIdGMpz9hLA3E58ehKmr5pvC2FY7vyHz0aoAb9ITVljjF6ShBy lD9UmU4CCaLFvoo/xGkLVq5aeHWhd+BEQmpD8KBInvOtwutUTk8pWnq72 s27nugqYr0tCu8hDBIovtQSD0+F8GvfZ/Aduy/P8jMIE4qZ3DsH7APN25 x/rc5xwXoOCXjN8l4LMdpcQMHka908ebRHCRObKnLtE6upaYr504RIlh0 q6a69hp1XkFW7wUscmOYGEbb0J14Sztu3YvNB322w7vKOLD2olPlQY3Sx aGza5DNi3F7q9qPuyo0F9tIuk1sHgP2I9wXf5+rDiD6+bpRnbSqy0Iqkt A==; IronPort-SDR: 1MEXSFKjOz2M/BV9Yu9eXPthSS68paL8G47mY7HNBLxAM2QT7dKCzVBeCNgSSunFeq4nvxYji1 Q8vSZSZN/RTR7DyaU6EAm90kkDub+HVSz2jdVqfHtPi8ArRvkqsb+4SB5KBmAZD5xRtXyyV4IK z3nCWvN1RiO/Hjs3DG045EekGx4frpMk4l6flDuxH1WmW72iOckhdp+mzFehRJPFL/XHx+ULwL UT6129vODLW3RVq8cE0LpZ+JCsX45yUEQfnZqlYOEbtXLSeEBXLkJhukociGtwXvRtuo0IVW/S 0Pk= X-IronPort-AV: E=Sophos;i="5.77,456,1596524400"; d="scan'208";a="92725631" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 06 Nov 2020 02:53:21 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Fri, 6 Nov 2020 02:53:20 -0700 Received: from m18063-ThinkPad-T460p.microchip.com (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.1979.3 via Frontend Transport; Fri, 6 Nov 2020 02:53:16 -0700 From: Claudiu Beznea To: , , , , , Subject: [PATCH 1/6] regulator: core: validate selector against linear_min_sel Date: Fri, 6 Nov 2020 11:52:59 +0200 Message-ID: <1604656384-827-2-git-send-email-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1604656384-827-1-git-send-email-claudiu.beznea@microchip.com> References: <1604656384-827-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-20201106_095329_377017_50430230 X-CRM114-Status: GOOD ( 12.59 ) 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: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Claudiu Beznea Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org There are regulators whose 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 f258ded39ce0..19a330492884 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];