Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1650782 > unrolled thread

[PATCH 1/3] phy: twl4030-usb: undo usb_add_phy_dev in error path

Started byUwe Kleine-König <u.kleine-koenig@pengutronix.de>
First post2017-05-25 22:00 +0200
Last post2017-05-25 22:00 +0200
Articles 3 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH 1/3] phy: twl4030-usb: undo usb_add_phy_dev in error path Uwe Kleine-König          <u.kleine-koenig@pengutronix.de> - 2017-05-25 22:00 +0200
    [PATCH 2/3] phy: twl4030-usb: handle usb_add_phy_dev return value Uwe Kleine-König          <u.kleine-koenig@pengutronix.de> - 2017-05-25 22:00 +0200
    [PATCH 3/3] phy: twl4030-usb: propagate actual error on regulator lookup Uwe Kleine-König          <u.kleine-koenig@pengutronix.de> - 2017-05-25 22:00 +0200

#1650782 — [PATCH 1/3] phy: twl4030-usb: undo usb_add_phy_dev in error path

FromUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Date2017-05-25 22:00 +0200
Subject[PATCH 1/3] phy: twl4030-usb: undo usb_add_phy_dev in error path
Message-ID<tL75o-40J-9@gated-at.bofh.it>
usb_add_phy_dev adds the passed phy to a list. When twl4030_usb_probe
fails this must be undone otherwise this results in a use after free
when the list is travered the next time.

Fixes: 6747caa76cab ("usb: phy: twl4030: use the new generic PHY framework")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/phy/phy-twl4030-usb.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/phy-twl4030-usb.c b/drivers/phy/phy-twl4030-usb.c
index 2990b3965460..07cb0150d008 100644
--- a/drivers/phy/phy-twl4030-usb.c
+++ b/drivers/phy/phy-twl4030-usb.c
@@ -750,13 +750,16 @@ static int twl4030_usb_probe(struct platform_device *pdev)
 	if (status < 0) {
 		dev_dbg(&pdev->dev, "can't get IRQ %d, err %d\n",
 			twl->irq, status);
+		usb_remove_phy(&twl->phy);
 		return status;
 	}
 
 	if (pdata)
 		err = phy_create_lookup(phy, "usb", "musb-hdrc.0");
-	if (err)
+	if (err) {
+		usb_remove_phy(&twl->phy);
 		return err;
+	}
 
 	pm_runtime_mark_last_busy(&pdev->dev);
 	pm_runtime_put_autosuspend(twl->dev);
-- 
2.11.0

[toc] | [next] | [standalone]


#1650784 — [PATCH 2/3] phy: twl4030-usb: handle usb_add_phy_dev return value

FromUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Date2017-05-25 22:00 +0200
Subject[PATCH 2/3] phy: twl4030-usb: handle usb_add_phy_dev return value
Message-ID<tL75o-40J-13@gated-at.bofh.it>
In reply to#1650782
usb_add_phy_dev can fail, so propagate this error instead of ignoring
that.

Fixes: 6747caa76cab ("usb: phy: twl4030: use the new generic PHY framework")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/phy/phy-twl4030-usb.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/phy-twl4030-usb.c b/drivers/phy/phy-twl4030-usb.c
index 07cb0150d008..6aefbd55fcee 100644
--- a/drivers/phy/phy-twl4030-usb.c
+++ b/drivers/phy/phy-twl4030-usb.c
@@ -723,7 +723,10 @@ static int twl4030_usb_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "ldo init failed\n");
 		return err;
 	}
-	usb_add_phy_dev(&twl->phy);
+
+	err = usb_add_phy_dev(&twl->phy);
+	if (err)
+		return err;
 
 	platform_set_drvdata(pdev, twl);
 	if (device_create_file(&pdev->dev, &dev_attr_vbus))
-- 
2.11.0

[toc] | [prev] | [next] | [standalone]


#1650785 — [PATCH 3/3] phy: twl4030-usb: propagate actual error on regulator lookup

FromUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Date2017-05-25 22:00 +0200
Subject[PATCH 3/3] phy: twl4030-usb: propagate actual error on regulator lookup
Message-ID<tL75o-40J-11@gated-at.bofh.it>
In reply to#1650782
devm_regulator_get returns an error code, return this one to the caller
instead of -ENODEV. This fixes deferred probe.

Fixes: 6747caa76cab ("usb: phy: twl4030: use the new generic PHY framework")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/phy/phy-twl4030-usb.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/phy/phy-twl4030-usb.c b/drivers/phy/phy-twl4030-usb.c
index 6aefbd55fcee..422232aac0b2 100644
--- a/drivers/phy/phy-twl4030-usb.c
+++ b/drivers/phy/phy-twl4030-usb.c
@@ -499,7 +499,7 @@ static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
 
 	twl->usb3v1 = devm_regulator_get(twl->dev, "usb3v1");
 	if (IS_ERR(twl->usb3v1))
-		return -ENODEV;
+		return PTR_ERR(twl->usb3v1);
 
 	twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB3V1_TYPE);
 
@@ -508,7 +508,7 @@ static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
 
 	twl->usb1v5 = devm_regulator_get(twl->dev, "usb1v5");
 	if (IS_ERR(twl->usb1v5))
-		return -ENODEV;
+		return PTR_ERR(twl->usb1v5);
 
 	twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V5_TYPE);
 
@@ -517,7 +517,7 @@ static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
 
 	twl->usb1v8 = devm_regulator_get(twl->dev, "usb1v8");
 	if (IS_ERR(twl->usb1v8))
-		return -ENODEV;
+		return PTR_ERR(twl->usb1v8);
 
 	twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V8_TYPE);
 
-- 
2.11.0

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web