Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1783695pxp; Mon, 7 Mar 2022 02:13:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJz+AuzQTYumyoGtaVi/N0c745CglE5QGjYqVDP9usVIvXGN7NYVraGTHbxAP5KR6QvNZP6Q X-Received: by 2002:a17:906:7852:b0:5bb:1bdb:e95f with SMTP id p18-20020a170906785200b005bb1bdbe95fmr8716531ejm.435.1646647995169; Mon, 07 Mar 2022 02:13:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646647995; cv=none; d=google.com; s=arc-20160816; b=0nERW65ULI4CLXl/hP5EAN1yhDg+GC9cWeH3w0oDiuSZxvDud6XP2yWddPNVOrVAL2 OExfaZE3OGkT8mSZma5lhCj9DgkArrrxztavw5V1bTOQ0GUv9Oyz7wwtrP31Nh0oxU35 XCuq+dNHpxP+UmNut6q4aP/gIQwSn8peYgQN77OxDsCafNXRrbQF8qXJNB/lrGrMtIx8 eAqrDCV0gKQKnPKW9YQ06bfJb/khfueQNheBSzc+f+npFbslLMvp9J8CsDWDujFCd286 xScfHUC2JeEFVx5mj9woFCLP3+cfUeCcJfE7Xtv0VjfFgX2TwEW520aZ9MWMfU8bzvhw innQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=F8Ep93ldnWl8QaPvQEGr+kYo8mqd7yy4xZr0rnI+m6o=; b=pOgJCT45NOa+r9cF8uKro5s7OynuU31SrGxlTlbe/og7sH6C82Cw+B7UXL7niKRp4P X5YhJgMF7eDiADqP0UBn4qjed7kiBjHIHqinHCW4tm2anyTWocNapneoBNcaORCh9D+2 TW53slECkU/QnJ9aDMEAYIUFvSussOuiOLDp96u7I5f/6YbEOZt42fL2OfSmGR8RCldN pQ5iMj3aO8KD4r1bp7k9UqxH0RguZwxAoilcynGFrLSylDlD17VE2IqWT9qJHmNL2n3K umUDE/oRnqQpwj8N2ryfmwC+Kv9JdM9XC2nWPsZ8NFEgDnFaxr4qgOBK984iD5FPWtxQ 3LZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="W/A4XOgi"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e3-20020a17090658c300b006cf034a8f28si9029060ejs.147.2022.03.07.02.12.52; Mon, 07 Mar 2022 02:13:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="W/A4XOgi"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236402AbiCGJoD (ORCPT + 99 others); Mon, 7 Mar 2022 04:44:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237838AbiCGJdP (ORCPT ); Mon, 7 Mar 2022 04:33:15 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EEE16B0B7; Mon, 7 Mar 2022 01:30:14 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0AC04611D3; Mon, 7 Mar 2022 09:30:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F12AEC340E9; Mon, 7 Mar 2022 09:30:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646645412; bh=S8+fvjACVMr0G7mDmqfilSIpGPjj3mkokKpLMNa4BWg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W/A4XOgiOmR3kVl7u/WZxrJwWc/Phw0wf+QoBA/4q4s00QOc36mBMm5Q4C4r8gFt9 kzkyoc0scnMmugFwsWigiMdThj6MjbEg/5euF9XPZVCyqXzgjmAY4B2LhJ5zipqvBa 3ae0vib9l6Dlpf2mSKegMp3kwnobUKCsDs10fQww= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oliver Barta , Mark Brown , Sasha Levin Subject: [PATCH 5.10 006/105] regulator: core: fix false positive in regulator_late_cleanup() Date: Mon, 7 Mar 2022 10:18:09 +0100 Message-Id: <20220307091644.363434127@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307091644.179885033@linuxfoundation.org> References: <20220307091644.179885033@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Oliver Barta [ Upstream commit 4e2a354e3775870ca823f1fb29bbbffbe11059a6 ] The check done by regulator_late_cleanup() to detect whether a regulator is on was inconsistent with the check done by _regulator_is_enabled(). While _regulator_is_enabled() takes the enable GPIO into account, regulator_late_cleanup() was not doing that. This resulted in a false positive, e.g. when a GPIO-controlled fixed regulator was used, which was not enabled at boot time, e.g. reg_disp_1v2: reg_disp_1v2 { compatible = "regulator-fixed"; regulator-name = "display_1v2"; regulator-min-microvolt = <1200000>; regulator-max-microvolt = <1200000>; gpio = <&tlmm 148 0>; enable-active-high; }; Such regulator doesn't have an is_enabled() operation. Nevertheless it's state can be determined based on the enable GPIO. The check in regulator_late_cleanup() wrongly assumed that the regulator is on and tried to disable it. Signed-off-by: Oliver Barta Link: https://lore.kernel.org/r/20220208084645.8686-1-oliver.barta@aptiv.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/regulator/core.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 043b5f63b94a1..2c48e55c4104e 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -5862,9 +5862,8 @@ core_initcall(regulator_init); static int regulator_late_cleanup(struct device *dev, void *data) { struct regulator_dev *rdev = dev_to_rdev(dev); - const struct regulator_ops *ops = rdev->desc->ops; struct regulation_constraints *c = rdev->constraints; - int enabled, ret; + int ret; if (c && c->always_on) return 0; @@ -5877,14 +5876,8 @@ static int regulator_late_cleanup(struct device *dev, void *data) if (rdev->use_count) goto unlock; - /* If we can't read the status assume it's always on. */ - if (ops->is_enabled) - enabled = ops->is_enabled(rdev); - else - enabled = 1; - - /* But if reading the status failed, assume that it's off. */ - if (enabled <= 0) + /* If reading the status failed, assume that it's off. */ + if (_regulator_is_enabled(rdev) <= 0) goto unlock; if (have_full_constraints()) { -- 2.34.1