From patchwork Mon Sep 2 17:22:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 172763 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp4547595ily; Mon, 2 Sep 2019 10:22:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzzOWJZz5DHjHNSrbjAm13B6vOlG2iATCR8/BMh3iThzz918wOBLyGNeL2hYTOk0St18YSM X-Received: by 2002:a63:3c5:: with SMTP id 188mr25569912pgd.394.1567444956178; Mon, 02 Sep 2019 10:22:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567444956; cv=none; d=google.com; s=arc-20160816; b=zb7cwpQMporMe0Z8Z6vvtV3JXb5Db0UgAMn0bqkHqCbesBSxzbUNHpfMSxwSpYQKhq gK78A7uTGJwATTBRJh7wVXO/+jl4d6SF2pR/dqpzprGxkDPpsvkNpyVZSzLXi6pE47n6 UVoRY22mD9zx2p80C98CaBau6Hw4/8WfB3T66IgJ6bGv0yZCwWbzeXvlNQsuXx3/zDJL QVM8fwts1J1OSqpnYaB4ikTZ6xjoMHcjQkgXZgAP8SuplQX79IGhkN+qMpn5IUKJFNon ul2VYgtiIFaSL4qWEsQ6H0vaKmpwPpxluEeNXt77+a0+FeYou0GxB7yy+k9zTJw5zR2b 5Vtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Ge4iDkVXLJAE0tqMDUvKSuDj6sip/kNFFFYp4OhwDS4=; b=HNpKAw3UCjkHT/Lt2PkbUt/fSt525vSzpC99q2qvG38XF4OPXI4G3DW8HlbyE8Qh5B A+ZyEIgYo5uH3vYViaargmJJCuCejKYXzn6n11LQjs9EKyB58eTAd5OhYvOmaDZ5ULLL I+Hb0da6hJkyTQJjegNPQtytEUUFHfvAaARxEws3xzZSx8zqsDyfzZd8IGuI/j8/xWch t3kLOQr24MTlme5epTdXfX7unn1102UJMImqHz7CxjSDNNIx+s9JUnZTaHmt/mPAvw2q wSWpBcuA44yeRQdr/TMQAMrUdQ8yf13e45jc0wr3Vbol9AVKISyE8SzPf8nBo+LXd28l hviw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@sirena.org.uk header.s=20170815-heliosphere header.b=i0CMNhgr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 61si12128928plb.270.2019.09.02.10.22.35; Mon, 02 Sep 2019 10:22:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@sirena.org.uk header.s=20170815-heliosphere header.b=i0CMNhgr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726599AbfIBRWe (ORCPT + 28 others); Mon, 2 Sep 2019 13:22:34 -0400 Received: from heliosphere.sirena.org.uk ([172.104.155.198]:42456 "EHLO heliosphere.sirena.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726185AbfIBRWe (ORCPT ); Mon, 2 Sep 2019 13:22:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sirena.org.uk; s=20170815-heliosphere; h=Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Ge4iDkVXLJAE0tqMDUvKSuDj6sip/kNFFFYp4OhwDS4=; b=i0CMNhgrLirnfNGlywpG5eJSA RQdtBob8zHVzDgM5/+ggJ6fkWt+1KC1FVc0g7K5V7iVEJ0/LDsvtOiKbTl8ZKU491Of/Z2BUe67s0 1a6nYD1guVqtOY3V4GqtyMD53SdfkjTJwZSOWxOhFNhoIBWmQT0zhGpVatc3dkRvg2F8U=; Received: from cpc102320-sgyl38-2-0-cust46.18-2.cable.virginm.net ([82.37.168.47] helo=ypsilon.sirena.org.uk) by heliosphere.sirena.org.uk with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1i4q29-0003rT-P9; Mon, 02 Sep 2019 17:22:29 +0000 Received: by ypsilon.sirena.org.uk (Postfix, from userid 1000) id 047D92742CB7; Mon, 2 Sep 2019 18:22:28 +0100 (BST) From: Mark Brown To: Hans de Goede , Jens Axboe Cc: linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Brown Subject: [PATCH] ata: libahci_platform: Fix regulator_get_optional() misuse Date: Mon, 2 Sep 2019 18:22:24 +0100 Message-Id: <20190902172224.49989-1-broonie@kernel.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This driver is using regulator_get_optional() to handle all the supplies that it handles, and only ever enables and disables all supplies en masse without ever doing any other configuration of the device to handle missing power. These are clear signs that the API is being misused - it should only be used for supplies that may be physically absent from the system and in these cases the hardware usually needs different configuration if the supply is missing. Instead use normal regualtor_get(), if the supply is not described in DT then the framework will substitute a dummy regulator in so no special handling is needed by the consumer driver. In the case of the PHY regulator the handling in the driver is a hack to deal with integrated PHYs; the supplies are only optional in the sense that that there's some confusion in the code about where they're bound to. >From a code point of view they function exactly as normal supplies so can be treated as such. It'd probably be better to model this by instantiating a PHY object for integrated PHYs. Signed-off-by: Mark Brown --- drivers/ata/libahci_platform.c | 38 +++++++++++++--------------------- 1 file changed, 14 insertions(+), 24 deletions(-) -- 2.20.1 diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c index 9e9583a6bba9..57882b3e46eb 100644 --- a/drivers/ata/libahci_platform.c +++ b/drivers/ata/libahci_platform.c @@ -153,17 +153,13 @@ int ahci_platform_enable_regulators(struct ahci_host_priv *hpriv) { int rc, i; - if (hpriv->ahci_regulator) { - rc = regulator_enable(hpriv->ahci_regulator); - if (rc) - return rc; - } + rc = regulator_enable(hpriv->ahci_regulator); + if (rc) + return rc; - if (hpriv->phy_regulator) { - rc = regulator_enable(hpriv->phy_regulator); - if (rc) - goto disable_ahci_pwrs; - } + rc = regulator_enable(hpriv->phy_regulator); + if (rc) + goto disable_ahci_pwrs; for (i = 0; i < hpriv->nports; i++) { if (!hpriv->target_pwrs[i]) @@ -181,11 +177,9 @@ int ahci_platform_enable_regulators(struct ahci_host_priv *hpriv) if (hpriv->target_pwrs[i]) regulator_disable(hpriv->target_pwrs[i]); - if (hpriv->phy_regulator) - regulator_disable(hpriv->phy_regulator); + regulator_disable(hpriv->phy_regulator); disable_ahci_pwrs: - if (hpriv->ahci_regulator) - regulator_disable(hpriv->ahci_regulator); + regulator_disable(hpriv->ahci_regulator); return rc; } EXPORT_SYMBOL_GPL(ahci_platform_enable_regulators); @@ -207,10 +201,8 @@ void ahci_platform_disable_regulators(struct ahci_host_priv *hpriv) regulator_disable(hpriv->target_pwrs[i]); } - if (hpriv->ahci_regulator) - regulator_disable(hpriv->ahci_regulator); - if (hpriv->phy_regulator) - regulator_disable(hpriv->phy_regulator); + regulator_disable(hpriv->ahci_regulator); + regulator_disable(hpriv->phy_regulator); } EXPORT_SYMBOL_GPL(ahci_platform_disable_regulators); /** @@ -359,7 +351,7 @@ static int ahci_platform_get_regulator(struct ahci_host_priv *hpriv, u32 port, struct regulator *target_pwr; int rc = 0; - target_pwr = regulator_get_optional(dev, "target"); + target_pwr = regulator_get(dev, "target"); if (!IS_ERR(target_pwr)) hpriv->target_pwrs[port] = target_pwr; @@ -436,16 +428,14 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev, hpriv->clks[i] = clk; } - hpriv->ahci_regulator = devm_regulator_get_optional(dev, "ahci"); + hpriv->ahci_regulator = devm_regulator_get(dev, "ahci"); if (IS_ERR(hpriv->ahci_regulator)) { rc = PTR_ERR(hpriv->ahci_regulator); - if (rc == -EPROBE_DEFER) + if (rc != 0) goto err_out; - rc = 0; - hpriv->ahci_regulator = NULL; } - hpriv->phy_regulator = devm_regulator_get_optional(dev, "phy"); + hpriv->phy_regulator = devm_regulator_get(dev, "phy"); if (IS_ERR(hpriv->phy_regulator)) { rc = PTR_ERR(hpriv->phy_regulator); if (rc == -EPROBE_DEFER)