Skip to content

Commit 962399b

Browse files
broonieaxboe
authored andcommitted
ata: libahci_platform: Fix regulator_get_optional() misuse
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. Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 7ce23e8 commit 962399b

1 file changed

Lines changed: 14 additions & 24 deletions

File tree

‎drivers/ata/libahci_platform.c‎

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,13 @@ int ahci_platform_enable_regulators(struct ahci_host_priv *hpriv)
153153
{
154154
int rc, i;
155155

156-
if (hpriv->ahci_regulator) {
157-
rc = regulator_enable(hpriv->ahci_regulator);
158-
if (rc)
159-
return rc;
160-
}
156+
rc = regulator_enable(hpriv->ahci_regulator);
157+
if (rc)
158+
return rc;
161159

162-
if (hpriv->phy_regulator) {
163-
rc = regulator_enable(hpriv->phy_regulator);
164-
if (rc)
165-
goto disable_ahci_pwrs;
166-
}
160+
rc = regulator_enable(hpriv->phy_regulator);
161+
if (rc)
162+
goto disable_ahci_pwrs;
167163

168164
for (i = 0; i < hpriv->nports; i++) {
169165
if (!hpriv->target_pwrs[i])
@@ -181,11 +177,9 @@ int ahci_platform_enable_regulators(struct ahci_host_priv *hpriv)
181177
if (hpriv->target_pwrs[i])
182178
regulator_disable(hpriv->target_pwrs[i]);
183179

184-
if (hpriv->phy_regulator)
185-
regulator_disable(hpriv->phy_regulator);
180+
regulator_disable(hpriv->phy_regulator);
186181
disable_ahci_pwrs:
187-
if (hpriv->ahci_regulator)
188-
regulator_disable(hpriv->ahci_regulator);
182+
regulator_disable(hpriv->ahci_regulator);
189183
return rc;
190184
}
191185
EXPORT_SYMBOL_GPL(ahci_platform_enable_regulators);
@@ -207,10 +201,8 @@ void ahci_platform_disable_regulators(struct ahci_host_priv *hpriv)
207201
regulator_disable(hpriv->target_pwrs[i]);
208202
}
209203

210-
if (hpriv->ahci_regulator)
211-
regulator_disable(hpriv->ahci_regulator);
212-
if (hpriv->phy_regulator)
213-
regulator_disable(hpriv->phy_regulator);
204+
regulator_disable(hpriv->ahci_regulator);
205+
regulator_disable(hpriv->phy_regulator);
214206
}
215207
EXPORT_SYMBOL_GPL(ahci_platform_disable_regulators);
216208
/**
@@ -359,7 +351,7 @@ static int ahci_platform_get_regulator(struct ahci_host_priv *hpriv, u32 port,
359351
struct regulator *target_pwr;
360352
int rc = 0;
361353

362-
target_pwr = regulator_get_optional(dev, "target");
354+
target_pwr = regulator_get(dev, "target");
363355

364356
if (!IS_ERR(target_pwr))
365357
hpriv->target_pwrs[port] = target_pwr;
@@ -436,16 +428,14 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,
436428
hpriv->clks[i] = clk;
437429
}
438430

439-
hpriv->ahci_regulator = devm_regulator_get_optional(dev, "ahci");
431+
hpriv->ahci_regulator = devm_regulator_get(dev, "ahci");
440432
if (IS_ERR(hpriv->ahci_regulator)) {
441433
rc = PTR_ERR(hpriv->ahci_regulator);
442-
if (rc == -EPROBE_DEFER)
434+
if (rc != 0)
443435
goto err_out;
444-
rc = 0;
445-
hpriv->ahci_regulator = NULL;
446436
}
447437

448-
hpriv->phy_regulator = devm_regulator_get_optional(dev, "phy");
438+
hpriv->phy_regulator = devm_regulator_get(dev, "phy");
449439
if (IS_ERR(hpriv->phy_regulator)) {
450440
rc = PTR_ERR(hpriv->phy_regulator);
451441
if (rc == -EPROBE_DEFER)

0 commit comments

Comments
 (0)