diff mbox series

[V3,1/3] pinctrl: ti: iodelay: Use scope based of_node_put() cleanups

Message ID 20240627131721.678727-2-peng.fan@oss.nxp.com (mailing list archive)
State New
Headers show
Series pinctrl: use scope based of_node_put | expand

Commit Message

Peng Fan (OSS) June 27, 2024, 1:17 p.m. UTC
From: Peng Fan <peng.fan@nxp.com>

Use scope based of_node_put() cleanup to simplify code.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/pinctrl/ti/pinctrl-ti-iodelay.c | 43 +++++++++----------------
 1 file changed, 15 insertions(+), 28 deletions(-)

Comments

Uwe Kleine-König June 28, 2024, 10:51 a.m. UTC | #1
Hello Peng,

On Thu, Jun 27, 2024 at 09:17:19PM +0800, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan@nxp.com>
> 
> Use scope based of_node_put() cleanup to simplify code.
> 
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
>  drivers/pinctrl/ti/pinctrl-ti-iodelay.c | 43 +++++++++----------------
>  1 file changed, 15 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/pinctrl/ti/pinctrl-ti-iodelay.c b/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
> index ef9758638501..f5e5a23d2226 100644
> --- a/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
> +++ b/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
> @@ -822,53 +822,48 @@ MODULE_DEVICE_TABLE(of, ti_iodelay_of_match);
>  static int ti_iodelay_probe(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
> -	struct device_node *np = of_node_get(dev->of_node);
> +	struct device_node *np __free(device_node) = of_node_get(dev->of_node);

of_node_put? -------------------------------------------^

Best regards
Uwe
Peng Fan June 29, 2024, 1:32 a.m. UTC | #2
> Subject: Re: [PATCH V3 1/3] pinctrl: ti: iodelay: Use scope based
> of_node_put() cleanups
> 
> Hello Peng,
> 
> On Thu, Jun 27, 2024 at 09:17:19PM +0800, Peng Fan (OSS) wrote:
> > From: Peng Fan <peng.fan@nxp.com>
> >
> > Use scope based of_node_put() cleanup to simplify code.
> >
> > Signed-off-by: Peng Fan <peng.fan@nxp.com>
> > ---
> >  drivers/pinctrl/ti/pinctrl-ti-iodelay.c | 43
> > +++++++++----------------
> >  1 file changed, 15 insertions(+), 28 deletions(-)
> >
> > diff --git a/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
> > b/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
> > index ef9758638501..f5e5a23d2226 100644
> > --- a/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
> > +++ b/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
> > @@ -822,53 +822,48 @@ MODULE_DEVICE_TABLE(of,
> ti_iodelay_of_match);
> > static int ti_iodelay_probe(struct platform_device *pdev)  {
> >  	struct device *dev = &pdev->dev;
> > -	struct device_node *np = of_node_get(dev->of_node);
> > +	struct device_node *np __free(device_node) =
> > +of_node_get(dev->of_node);
> 
> of_node_put? -------------------------------------------^

You mean use of_node_put here?
of_node_get should be used here. The __free will automatically
do of_node_put when function return.

Thanks,
Peng.

> 
> Best regards
> Uwe
Uwe Kleine-König June 29, 2024, 8:08 a.m. UTC | #3
Hello,

On Sat, Jun 29, 2024 at 01:32:15AM +0000, Peng Fan wrote:
> > Subject: Re: [PATCH V3 1/3] pinctrl: ti: iodelay: Use scope based
> > of_node_put() cleanups
> > 
> > Hello Peng,
> > 
> > On Thu, Jun 27, 2024 at 09:17:19PM +0800, Peng Fan (OSS) wrote:
> > > From: Peng Fan <peng.fan@nxp.com>
> > >
> > > Use scope based of_node_put() cleanup to simplify code.
> > >
> > > Signed-off-by: Peng Fan <peng.fan@nxp.com>
> > > ---
> > >  drivers/pinctrl/ti/pinctrl-ti-iodelay.c | 43
> > > +++++++++----------------
> > >  1 file changed, 15 insertions(+), 28 deletions(-)
> > >
> > > diff --git a/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
> > > b/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
> > > index ef9758638501..f5e5a23d2226 100644
> > > --- a/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
> > > +++ b/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
> > > @@ -822,53 +822,48 @@ MODULE_DEVICE_TABLE(of,
> > ti_iodelay_of_match);
> > > static int ti_iodelay_probe(struct platform_device *pdev)  {
> > >  	struct device *dev = &pdev->dev;
> > > -	struct device_node *np = of_node_get(dev->of_node);
> > > +	struct device_node *np __free(device_node) =
> > > +of_node_get(dev->of_node);
> > 
> > of_node_put? -------------------------------------------^
> 
> You mean use of_node_put here?
> of_node_get should be used here. The __free will automatically
> do of_node_put when function return.

Ah, I misinterpreted the syntax. I thought your code registers
of_node_get() as cleanup handler.

Sorry for the noise,
Uwe
diff mbox series

Patch

diff --git a/drivers/pinctrl/ti/pinctrl-ti-iodelay.c b/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
index ef9758638501..f5e5a23d2226 100644
--- a/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
+++ b/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
@@ -822,53 +822,48 @@  MODULE_DEVICE_TABLE(of, ti_iodelay_of_match);
 static int ti_iodelay_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
-	struct device_node *np = of_node_get(dev->of_node);
+	struct device_node *np __free(device_node) = of_node_get(dev->of_node);
 	struct resource *res;
 	struct ti_iodelay_device *iod;
-	int ret = 0;
+	int ret;
 
 	if (!np) {
-		ret = -EINVAL;
 		dev_err(dev, "No OF node\n");
-		goto exit_out;
+		return -EINVAL;
 	}
 
 	iod = devm_kzalloc(dev, sizeof(*iod), GFP_KERNEL);
-	if (!iod) {
-		ret = -ENOMEM;
-		goto exit_out;
-	}
+	if (!iod)
+		return -ENOMEM;
+
 	iod->dev = dev;
 	iod->reg_data = device_get_match_data(dev);
 	if (!iod->reg_data) {
-		ret = -EINVAL;
 		dev_err(dev, "No DATA match\n");
-		goto exit_out;
+		return -EINVAL;
 	}
 
 	/* So far We can assume there is only 1 bank of registers */
 	iod->reg_base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
-	if (IS_ERR(iod->reg_base)) {
-		ret = PTR_ERR(iod->reg_base);
-		goto exit_out;
-	}
+	if (IS_ERR(iod->reg_base))
+		return PTR_ERR(iod->reg_base);
+
 	iod->phys_base = res->start;
 
 	iod->regmap = devm_regmap_init_mmio(dev, iod->reg_base,
 					    iod->reg_data->regmap_config);
 	if (IS_ERR(iod->regmap)) {
 		dev_err(dev, "Regmap MMIO init failed.\n");
-		ret = PTR_ERR(iod->regmap);
-		goto exit_out;
+		return PTR_ERR(iod->regmap);
 	}
 
 	ret = ti_iodelay_pinconf_init_dev(iod);
 	if (ret)
-		goto exit_out;
+		return ret;
 
 	ret = ti_iodelay_alloc_pins(dev, iod, res->start);
 	if (ret)
-		goto exit_out;
+		return ret;
 
 	iod->desc.pctlops = &ti_iodelay_pinctrl_ops;
 	/* no pinmux ops - we are pinconf */
@@ -879,20 +874,12 @@  static int ti_iodelay_probe(struct platform_device *pdev)
 	ret = devm_pinctrl_register_and_init(dev, &iod->desc, iod, &iod->pctl);
 	if (ret) {
 		dev_err(dev, "Failed to register pinctrl\n");
-		goto exit_out;
+		return ret;
 	}
 
 	platform_set_drvdata(pdev, iod);
 
-	ret = pinctrl_enable(iod->pctl);
-	if (ret)
-		goto exit_out;
-
-	return 0;
-
-exit_out:
-	of_node_put(np);
-	return ret;
+	return pinctrl_enable(iod->pctl);
 }
 
 /**