From patchwork Wed Nov 25 11:34:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 11931243 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=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,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 6C39CC5519F for ; Wed, 25 Nov 2020 11:35:47 +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 E513D206C0 for ; Wed, 25 Nov 2020 11:35:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="NIUDelZr"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="17FjSCzE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E513D206C0 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=jt04ao0MBYVZwBYZ+7yINTTcGJGu9uldtVyMWWPh1T4=; b=NIUDelZrZ+pqkAIUv1zvsPyF7 RBTVbzvyfAUzIRfe+hLaBPqKoUScwr5VLamEnSwVXNBYMTSmY0+48swBq1P07fiPK7IC/LEARa2I5 1bsL+FPYMGwZf5rJirFrTEVLKvd+md+b+pJEOeC4QtoWeXuqq7ZfH4xTMqEOYVT912GJ80VV9pe4G o2g3GrYsI4DJQ7xxqc+ZOOcQEBf0CnnuvcpVRRrN40oFzhAQZxcWGgDfPuYVCuB1x5H5n1DbjsPdM xqgvrlRHMTs/RKk6Eoy+LSLBmMf/1hc3wCb9igm+bZO3OiztcLgmZ8iYmEzjIYoHSfaRI9b3K2FdI bGoS/nc+A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kht3w-0001pH-BC; Wed, 25 Nov 2020 11:34:16 +0000 Received: from esa1.microchip.iphmx.com ([68.232.147.91]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kht3t-0001oo-OQ for linux-arm-kernel@lists.infradead.org; Wed, 25 Nov 2020 11:34:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1606304053; x=1637840053; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=AdPJ+J5keoI7FMAiLdNj/CT8Rb6ZvE+73VJf1DkHPS0=; b=17FjSCzE/9mrFAhx3CYYp5zYMFC6JXQEPDYdOyJH+YgrCwUV9q3ukz3a XNbf/md5pLFyqN/tzKhqEUiMerIlStVIqjWZM12wOowDzbABcC10JglSG LDjr2YbO6Sa9hB8tWUrO958c9QTOVL+2AYiGYXNyE10ArmICnuSgmjNoY 34zdw7YpdGoB5wWfF2cB49azZaeFzJcarg2fU8Uzma5goV+AfvJ3c9d2y 2JDnGl/b4QT5x0Y1jNBTn64z3bXz06UQsRjVLEl6qTUhr4/rUTxYJBgvy VwIhVB/8kWSli0NBti8mPF0swqifOoUGzFKKPrT9620hfzRufgCSf0Rfc A==; IronPort-SDR: t0kRFXRMypynMr+qGpu31740TObzazSqwB5ln8Aqz1+xQqtaxyt9N3FoO3JJg9pNwE7yPQHUpc 52PboiMEsQ13jzZ1E1K2/gqV6hMs7NAgd3bCEcTAc/vgCjVSF5VMMwYacQeOYcWd6uZHgEtgLZ N6Canrpuz+IouHMklAF3jerQwsIUtMjpBxipySusVNQKUF7P2vDy/p3vwMVYljgDZCyFu0NFs4 GjmpnQUrVXD7H+yznLKC81mUAets7Tp7zhUVJH1kz4q3kkgY2PZTNaEXwvH7rQTPLKrrsPX9IN HPE= X-IronPort-AV: E=Sophos;i="5.78,368,1599548400"; d="scan'208";a="104994999" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 25 Nov 2020 04:34:10 -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; Wed, 25 Nov 2020 04:34:10 -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; Wed, 25 Nov 2020 04:34:06 -0700 From: Claudiu Beznea To: , Subject: [PATCH] regulator: core: return zero for selectors lower than linear_min_sel Date: Wed, 25 Nov 2020 13:34:03 +0200 Message-ID: <1606304043-3227-1-git-send-email-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <20201124141136.GD4933@sirena.org.uk> References: <20201124141136.GD4933@sirena.org.uk> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201125_063413_949398_5AF9F7A8 X-CRM114-Status: GOOD ( 12.55 ) 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: Claudiu Beznea , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, jonathanh@nvidia.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Selectors lower than linear_min_sel should not be considered invalid. Thus return zero in case _regulator_list_voltage(), regulator_list_hardware_vsel() or regulator_list_voltage_table() receives such selectors as argument. Fixes: bdcd1177578c ("regulator: core: validate selector against linear_min_sel") Reported-by: Jon Hunter Signed-off-by: Claudiu Beznea --- drivers/regulator/core.c | 10 ++++++---- drivers/regulator/helpers.c | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 216b0cbce199..ca03d8e70bd1 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2956,9 +2956,10 @@ static int _regulator_list_voltage(struct regulator_dev *rdev, return rdev->desc->fixed_uV; if (ops->list_voltage) { - if (selector >= rdev->desc->n_voltages || - selector < rdev->desc->linear_min_sel) + if (selector >= rdev->desc->n_voltages) return -EINVAL; + if (selector < rdev->desc->linear_min_sel) + return 0; if (lock) regulator_lock(rdev); ret = ops->list_voltage(rdev, selector); @@ -3108,9 +3109,10 @@ 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 || - selector < rdev->desc->linear_min_sel) + if (selector >= rdev->desc->n_voltages) return -EINVAL; + if (selector < rdev->desc->linear_min_sel) + return 0; if (ops->set_voltage_sel != regulator_set_voltage_sel_regmap) return -EOPNOTSUPP; diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c index 974f1a63993d..f42b394a0c46 100644 --- a/drivers/regulator/helpers.c +++ b/drivers/regulator/helpers.c @@ -647,9 +647,10 @@ int regulator_list_voltage_table(struct regulator_dev *rdev, return -EINVAL; } - if (selector >= rdev->desc->n_voltages || - selector < rdev->desc->linear_min_sel) + if (selector >= rdev->desc->n_voltages) return -EINVAL; + if (selector < rdev->desc->linear_min_sel) + return 0; return rdev->desc->volt_table[selector]; }