Skip to contentSkip to conversation

usb: phy: phy-mxs-usb: Use of_device_get_match_data()

PATCH Superseded Fabio Estevam 2 participants 8 messages Nov 24, 2020 – Nov 25, 2020

Subsystems (3)
lore
Share & tools
lore

Fabio Estevam

author reviewer
#0 lore raw

PATCH 1/3 usb: phy: phy-mxs-usb: Use of_device_get_match_data()

The retrieval of driver data via of_device_get_match_data() can make the code simpler.

Use of_device_get_match_data() to simplify the code.

---
 drivers/usb/phy/phy-mxs-usb.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/usb/phy/phy-mxs-usb.c +1 -6
index 67b39dc62b37..8a262c5a0408 100644
@@ -714,14 +714,9 @@ static int mxs_phy_probe(struct platform_device *pdev)
 	struct clk *clk;
 	struct mxs_phy *mxs_phy;
 	int ret;
-	const struct of_device_id *of_id;
 	struct device_node *np = pdev->dev.of_node;
 	u32 val;
 
-	of_id = of_match_device(mxs_phy_dt_ids, &pdev->dev);
-	if (!of_id)
-		return -ENODEV;
-
 	base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(base))
 		return PTR_ERR(base);
@@ -797,7 +792,7 @@ static int mxs_phy_probe(struct platform_device *pdev)
 	mxs_phy->phy.charger_detect	= mxs_phy_charger_detect;
 
 	mxs_phy->clk = clk;
-	mxs_phy->data = of_id->data;
+	mxs_phy->data = of_device_get_match_data(&pdev->dev);
 
 	platform_set_drvdata(pdev, mxs_phy);
 
Signature · 1 line
2.17.1
author reviewer
#1 lore raw

PATCH 2/3 usb: chipidea: usbmisc_imx: Use of_device_get_match_data()

The retrieval of driver data via of_device_get_match_data() can make the code simpler.

Use of_device_get_match_data() to simplify the code.

---
 drivers/usb/chipidea/usbmisc_imx.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/usb/chipidea/usbmisc_imx.c +1 -6
index 6d8331e7da99..4545b23bda3f 100644
@@ -1134,11 +1134,6 @@ MODULE_DEVICE_TABLE(of, usbmisc_imx_dt_ids);
 static int usbmisc_imx_probe(struct platform_device *pdev)
 {
 	struct imx_usbmisc *data;
-	const struct of_device_id *of_id;
-
-	of_id = of_match_device(usbmisc_imx_dt_ids, &pdev->dev);
-	if (!of_id)
-		return -ENODEV;
 
 	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
@@ -1150,7 +1145,7 @@ static int usbmisc_imx_probe(struct platform_device *pdev)
 	if (IS_ERR(data->base))
 		return PTR_ERR(data->base);
 
-	data->ops = (const struct usbmisc_ops *)of_id->data;
+	data->ops = of_device_get_match_data(&pdev->dev);
 	platform_set_drvdata(pdev, data);
 
 	return 0;
Signature · 1 line
2.17.1
author reviewer
#2 lore raw

PATCH 3/3 usb: chipidea: ci_hdrc_imx: Use of_device_get_match_data()

In reply to Fabio Estevam

The retrieval of driver data via of_device_get_match_data() can make the code simpler.

Use of_device_get_match_data() to simplify the code.

---
 drivers/usb/chipidea/ci_hdrc_imx.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/usb/chipidea/ci_hdrc_imx.c +1 -6
index 25c65accf089..8fa712148e5d 100644
@@ -319,16 +319,11 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
 		.notify_event	= ci_hdrc_imx_notify_event,
 	};
 	int ret;
-	const struct of_device_id *of_id;
 	const struct ci_hdrc_imx_platform_flag *imx_platform_flag;
 	struct device_node *np = pdev->dev.of_node;
 	struct device *dev = &pdev->dev;
 
-	of_id = of_match_device(ci_hdrc_imx_dt_ids, dev);
-	if (!of_id)
-		return -ENODEV;
-
-	imx_platform_flag = of_id->data;
+	imx_platform_flag = of_device_get_match_data(&pdev->dev);
 
 	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
Signature · 1 line
2.17.1
#3 lore raw
In reply to Fabio Estevam
Quoted 30 lines · Fabio Estevam

The retrieval of driver data via of_device_get_match_data() can make the code simpler.

Use of_device_get_match_data() to simplify the code.

---
 drivers/usb/phy/phy-mxs-usb.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/usb/phy/phy-mxs-usb.c +0 -5
index 67b39dc62b37..8a262c5a0408 100644
@@ -714,14 +714,9 @@ static int mxs_phy_probe(struct platform_device *pdev)
 	struct clk *clk;
 	struct mxs_phy *mxs_phy;
 	int ret;
-	const struct of_device_id *of_id;
 	struct device_node *np = pdev->dev.of_node;
 	u32 val;
 
-	of_id = of_match_device(mxs_phy_dt_ids, &pdev->dev);
-	if (!of_id)
-		return -ENODEV;
-
 	base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(base))
 		return PTR_ERR(base);

drivers/usb/phy/phy-mxs-usb.c static int mxs_phy_probe(struct platform_device *pdev) · line 795

Quoted 5 lines
drivers/usb/phy/phy-mxs-usb.c +1 -1
@@ -797,7 +792,7 @@ static int mxs_phy_probe(struct platform_device *pdev)
 	mxs_phy->phy.charger_detect	= mxs_phy_charger_detect;
 
 	mxs_phy->clk = clk;
-	mxs_phy->data = of_id->data;
+	mxs_phy->data = of_device_get_match_data(&pdev->dev);

You may forget the error handling for it, eg, -ENODEV.

Peter

Quoted 6 lines
drivers/usb/phy/phy-mxs-usb.c +0 -0
 	platform_set_drvdata(pdev, mxs_phy);
 
Signature · 1 line
2.17.1
Signature · 2 lines
Thanks,
Peter Chen
author reviewer
#4 lore raw

Hi Peter,

Quoted 4 lines · Peter Chen

drivers/usb/phy/phy-mxs-usb.c static int mxs_phy_probe(struct platform_device *pdev) · line 795

Quoted 2 lines
drivers/usb/phy/phy-mxs-usb.c +1 -1
-     mxs_phy->data = of_id->data;
+     mxs_phy->data = of_device_get_match_data(&pdev->dev);

You may forget the error handling for it, eg, -ENODEV.

How can this happen?

#5 lore raw
Quoted 10 lines · Fabio Estevam

Hi Peter,

Quoted 4 lines · Peter Chen

drivers/usb/phy/phy-mxs-usb.c static int mxs_phy_probe(struct platform_device *pdev) · line 795

Quoted 2 lines
drivers/usb/phy/phy-mxs-usb.c +1 -1
-     mxs_phy->data = of_id->data;
+     mxs_phy->data = of_device_get_match_data(&pdev->dev);

You may forget the error handling for it, eg, -ENODEV.

How can this happen?

When adding the new SoCs, the new compatible is added at dts, but forget adding at device driver's of_device_id table?

Signature · 2 lines
Thanks,
Peter Chen
author reviewer
#6 lore raw
Quoted 2 lines · Peter Chen

When adding the new SoCs, the new compatible is added at dts, but forget adding at device driver's of_device_id table?

In this case, the probe function will not even be called if there is no matching.

Please see:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v5.10-rc5&id=e6c7c258f035ffec9d8a808c1bc34b6a5beae0ef

and
https://www.alsa-project.org/pipermail/alsa-devel/2017-January/117275.html

There is no need for doing a NULL check on of_device_get_match_data() on a DT-only driver.

Acked-by on v1 1/3
#7 lore raw
In reply to Fabio Estevam
Quoted 3 lines

Peter

Quoted 36 lines
---
 drivers/usb/phy/phy-mxs-usb.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/usb/phy/phy-mxs-usb.c +0 -5
index 67b39dc62b37..8a262c5a0408 100644
@@ -714,14 +714,9 @@ static int mxs_phy_probe(struct platform_device
 *pdev)
 	struct clk *clk;
 	struct mxs_phy *mxs_phy;
 	int ret;
-	const struct of_device_id *of_id;
 	struct device_node *np = pdev->dev.of_node;
 	u32 val;
 
-	of_id = of_match_device(mxs_phy_dt_ids, &pdev->dev);
-	if (!of_id)
-		return -ENODEV;
-
 	base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(base))
drivers/usb/phy/phy-mxs-usb.c +1 -2
 		return PTR_ERR(base);
@@ -797,7 +792,7 @@ static int mxs_phy_probe(struct platform_device
 *pdev)
 	mxs_phy->phy.charger_detect	= mxs_phy_charger_detect;
 
 	mxs_phy->clk = clk;
-	mxs_phy->data = of_id->data;
+	mxs_phy->data = of_device_get_match_data(&pdev->dev);
 
 	platform_set_drvdata(pdev, mxs_phy);
 
--

2.17.1