diff mbox series

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

Message ID 20201124163912.12074-1-festevam@gmail.com (mailing list archive)
State Superseded
Headers show
Series [1/3] usb: phy: phy-mxs-usb: Use of_device_get_match_data() | expand

Commit Message

Fabio Estevam Nov. 24, 2020, 4:39 p.m. UTC
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. 

Signed-off-by: Fabio Estevam <festevam@gmail.com>
---
 drivers/usb/phy/phy-mxs-usb.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

Comments

Peter Chen Nov. 25, 2020, 1:15 a.m. UTC | #1
On 20-11-24 13:39:10, Fabio Estevam wrote:
> 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. 
> 
> Signed-off-by: Fabio Estevam <festevam@gmail.com>
> ---
>  drivers/usb/phy/phy-mxs-usb.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/drivers/usb/phy/phy-mxs-usb.c b/drivers/usb/phy/phy-mxs-usb.c
> index 67b39dc62b37..8a262c5a0408 100644
> --- a/drivers/usb/phy/phy-mxs-usb.c
> +++ b/drivers/usb/phy/phy-mxs-usb.c
> @@ -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);

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

Peter
>  
>  	platform_set_drvdata(pdev, mxs_phy);
>  
> -- 
> 2.17.1
>
Fabio Estevam Nov. 25, 2020, 1:21 a.m. UTC | #2
Hi Peter,

On Tue, Nov 24, 2020 at 10:15 PM Peter Chen <peter.chen@nxp.com> wrote:

> > -     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?
Peter Chen Nov. 25, 2020, 1:58 a.m. UTC | #3
On 20-11-24 22:21:40, Fabio Estevam wrote:
> Hi Peter,
> 
> On Tue, Nov 24, 2020 at 10:15 PM Peter Chen <peter.chen@nxp.com> wrote:
> 
> > > -     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?
Fabio Estevam Nov. 25, 2020, 2:13 a.m. UTC | #4
On Tue, Nov 24, 2020 at 10:58 PM Peter Chen <peter.chen@nxp.com> wrote:

> 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.
Peter Chen Nov. 25, 2020, 4:48 a.m. UTC | #5
> 
> Signed-off-by: Fabio Estevam <festevam@gmail.com>

Acked-by: Peter Chen <peter.chen@nxp.com>

Peter
> ---
>  drivers/usb/phy/phy-mxs-usb.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/drivers/usb/phy/phy-mxs-usb.c b/drivers/usb/phy/phy-mxs-usb.c
> index 67b39dc62b37..8a262c5a0408 100644
> --- a/drivers/usb/phy/phy-mxs-usb.c
> +++ b/drivers/usb/phy/phy-mxs-usb.c
> @@ -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);
> 
> --
> 2.17.1
diff mbox series

Patch

diff --git a/drivers/usb/phy/phy-mxs-usb.c b/drivers/usb/phy/phy-mxs-usb.c
index 67b39dc62b37..8a262c5a0408 100644
--- a/drivers/usb/phy/phy-mxs-usb.c
+++ b/drivers/usb/phy/phy-mxs-usb.c
@@ -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);