Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

phy: core: fix wrong err handle for phy_power_on

If phy_pm_runtime_get_sync failed but we already
enable regulator, current code return directly without
doing regulator_disable. This patch fix this problem
and cleanup err handle of phy_power_on to be more readable.

Fixes: 3be88125d85d ("phy: core: Support regulator ...")
Cc: <stable@vger.kernel.org> # v3.18+
Cc: Roger Quadros <rogerq@ti.com>
Cc: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>

authored by

Shawn Lin and committed by
Kishon Vijay Abraham I
b82fcabe d896910f

+9 -7
+9 -7
drivers/phy/phy-core.c
··· 275 275 276 276 int phy_power_on(struct phy *phy) 277 277 { 278 - int ret; 278 + int ret = 0; 279 279 280 280 if (!phy) 281 - return 0; 281 + goto out; 282 282 283 283 if (phy->pwr) { 284 284 ret = regulator_enable(phy->pwr); 285 285 if (ret) 286 - return ret; 286 + goto out; 287 287 } 288 288 289 289 ret = phy_pm_runtime_get_sync(phy); 290 290 if (ret < 0 && ret != -ENOTSUPP) 291 - return ret; 291 + goto err_pm_sync; 292 + 292 293 ret = 0; /* Override possible ret == -ENOTSUPP */ 293 294 294 295 mutex_lock(&phy->mutex); ··· 297 296 ret = phy->ops->power_on(phy); 298 297 if (ret < 0) { 299 298 dev_err(&phy->dev, "phy poweron failed --> %d\n", ret); 300 - goto out; 299 + goto err_pwr_on; 301 300 } 302 301 } 303 302 ++phy->power_count; 304 303 mutex_unlock(&phy->mutex); 305 304 return 0; 306 305 307 - out: 306 + err_pwr_on: 308 307 mutex_unlock(&phy->mutex); 309 308 phy_pm_runtime_put_sync(phy); 309 + err_pm_sync: 310 310 if (phy->pwr) 311 311 regulator_disable(phy->pwr); 312 - 312 + out: 313 313 return ret; 314 314 } 315 315 EXPORT_SYMBOL_GPL(phy_power_on);