diff mbox series

[08/21] pinctrl: samsung: Use scope based of_node_put() cleanups

Message ID 20240501-pinctrl-cleanup-v1-8-797ceca46e5c@nxp.com (mailing list archive)
State New
Headers show
Series pinctrl: Use scope based of_node_put() cleanups | expand

Commit Message

Peng Fan (OSS) May 1, 2024, 12:56 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/samsung/pinctrl-exynos-arm.c |  3 +--
 drivers/pinctrl/samsung/pinctrl-exynos.c     | 16 ++++------------
 drivers/pinctrl/samsung/pinctrl-s3c64xx.c    |  8 ++------
 drivers/pinctrl/samsung/pinctrl-samsung.c    | 26 +++++++-------------------
 4 files changed, 14 insertions(+), 39 deletions(-)

Comments

Krzysztof Kozlowski May 1, 2024, 4:34 p.m. UTC | #1
On 01/05/2024 14:56, 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/samsung/pinctrl-exynos-arm.c |  3 +--
>  drivers/pinctrl/samsung/pinctrl-exynos.c     | 16 ++++------------
>  drivers/pinctrl/samsung/pinctrl-s3c64xx.c    |  8 ++------
>  drivers/pinctrl/samsung/pinctrl-samsung.c    | 26 +++++++-------------------
>  4 files changed, 14 insertions(+), 39 deletions(-)
> 
> diff --git a/drivers/pinctrl/samsung/pinctrl-exynos-arm.c b/drivers/pinctrl/samsung/pinctrl-exynos-arm.c
> index 85ddf49a5188..9a57b3ceb536 100644
> --- a/drivers/pinctrl/samsung/pinctrl-exynos-arm.c
> +++ b/drivers/pinctrl/samsung/pinctrl-exynos-arm.c
> @@ -56,7 +56,7 @@ s5pv210_retention_init(struct samsung_pinctrl_drv_data *drvdata,
>  		       const struct samsung_retention_data *data)
>  {
>  	struct samsung_retention_ctrl *ctrl;
> -	struct device_node *np;
> +	struct device_node *np __free(device_node) = NULL;
>  	void __iomem *clk_base;
>  
>  	ctrl = devm_kzalloc(drvdata->dev, sizeof(*ctrl), GFP_KERNEL);
> @@ -71,7 +71,6 @@ s5pv210_retention_init(struct samsung_pinctrl_drv_data *drvdata,
>  	}
>  
>  	clk_base = of_iomap(np, 0);
> -	of_node_put(np);

I don't think the code as simpler. Previous was very easy to read,
obvious, no error paths.

To me any conversion of such of_node_get immediately followed by
of_node_put is unwelcomed. Easy code is being  converted to complicated one.


Best regards,
Krzysztof
Peng Fan May 1, 2024, 11:25 p.m. UTC | #2
> Subject: Re: [PATCH 08/21] pinctrl: samsung: Use scope based of_node_put()
> cleanups
> 
> On 01/05/2024 14:56, 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/samsung/pinctrl-exynos-arm.c |  3 +--
> >  drivers/pinctrl/samsung/pinctrl-exynos.c     | 16 ++++------------
> >  drivers/pinctrl/samsung/pinctrl-s3c64xx.c    |  8 ++------
> >  drivers/pinctrl/samsung/pinctrl-samsung.c    | 26 +++++++-------------------
> >  4 files changed, 14 insertions(+), 39 deletions(-)
> >
> > diff --git a/drivers/pinctrl/samsung/pinctrl-exynos-arm.c
> > b/drivers/pinctrl/samsung/pinctrl-exynos-arm.c
> > index 85ddf49a5188..9a57b3ceb536 100644
> > --- a/drivers/pinctrl/samsung/pinctrl-exynos-arm.c
> > +++ b/drivers/pinctrl/samsung/pinctrl-exynos-arm.c
> > @@ -56,7 +56,7 @@ s5pv210_retention_init(struct
> samsung_pinctrl_drv_data *drvdata,
> >  		       const struct samsung_retention_data *data)  {
> >  	struct samsung_retention_ctrl *ctrl;
> > -	struct device_node *np;
> > +	struct device_node *np __free(device_node) = NULL;
> >  	void __iomem *clk_base;
> >
> >  	ctrl = devm_kzalloc(drvdata->dev, sizeof(*ctrl), GFP_KERNEL); @@
> > -71,7 +71,6 @@ s5pv210_retention_init(struct samsung_pinctrl_drv_data
> *drvdata,
> >  	}
> >
> >  	clk_base = of_iomap(np, 0);
> > -	of_node_put(np);
> 
> I don't think the code as simpler. Previous was very easy to read, obvious, no
> error paths.
> 
> To me any conversion of such of_node_get immediately followed by
> of_node_put is unwelcomed. Easy code is being  converted to complicated
> one.

ok. I will drop the changes to code pieces as you commented.

Thanks,
Peng.
> 
> 
> Best regards,
> Krzysztof
diff mbox series

Patch

diff --git a/drivers/pinctrl/samsung/pinctrl-exynos-arm.c b/drivers/pinctrl/samsung/pinctrl-exynos-arm.c
index 85ddf49a5188..9a57b3ceb536 100644
--- a/drivers/pinctrl/samsung/pinctrl-exynos-arm.c
+++ b/drivers/pinctrl/samsung/pinctrl-exynos-arm.c
@@ -56,7 +56,7 @@  s5pv210_retention_init(struct samsung_pinctrl_drv_data *drvdata,
 		       const struct samsung_retention_data *data)
 {
 	struct samsung_retention_ctrl *ctrl;
-	struct device_node *np;
+	struct device_node *np __free(device_node) = NULL;
 	void __iomem *clk_base;
 
 	ctrl = devm_kzalloc(drvdata->dev, sizeof(*ctrl), GFP_KERNEL);
@@ -71,7 +71,6 @@  s5pv210_retention_init(struct samsung_pinctrl_drv_data *drvdata,
 	}
 
 	clk_base = of_iomap(np, 0);
-	of_node_put(np);
 	if (!clk_base) {
 		pr_err("%s: failed to map clock registers\n", __func__);
 		return ERR_PTR(-EINVAL);
diff --git a/drivers/pinctrl/samsung/pinctrl-exynos.c b/drivers/pinctrl/samsung/pinctrl-exynos.c
index 871c1eb46ddf..3775999536e2 100644
--- a/drivers/pinctrl/samsung/pinctrl-exynos.c
+++ b/drivers/pinctrl/samsung/pinctrl-exynos.c
@@ -582,7 +582,7 @@  static void exynos_irq_demux_eint16_31(struct irq_desc *desc)
 __init int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d)
 {
 	struct device *dev = d->dev;
-	struct device_node *wkup_np = NULL;
+	struct device_node *wkup_np __free(device_node) = NULL;
 	struct device_node *np;
 	struct samsung_pin_bank *bank;
 	struct exynos_weint_data *weint_data;
@@ -612,17 +612,14 @@  __init int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d)
 
 		bank->irq_chip = devm_kmemdup(dev, irq_chip, sizeof(*irq_chip),
 					      GFP_KERNEL);
-		if (!bank->irq_chip) {
-			of_node_put(wkup_np);
+		if (!bank->irq_chip)
 			return -ENOMEM;
-		}
 		bank->irq_chip->chip.name = bank->name;
 
 		bank->irq_domain = irq_domain_create_linear(bank->fwnode,
 				bank->nr_pins, &exynos_eint_irqd_ops, bank);
 		if (!bank->irq_domain) {
 			dev_err(dev, "wkup irq domain add failed\n");
-			of_node_put(wkup_np);
 			return -ENXIO;
 		}
 
@@ -635,10 +632,8 @@  __init int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d)
 		weint_data = devm_kcalloc(dev,
 					  bank->nr_pins, sizeof(*weint_data),
 					  GFP_KERNEL);
-		if (!weint_data) {
-			of_node_put(wkup_np);
+		if (!weint_data)
 			return -ENOMEM;
-		}
 
 		for (idx = 0; idx < bank->nr_pins; ++idx) {
 			irq = irq_of_parse_and_map(to_of_node(bank->fwnode), idx);
@@ -655,13 +650,10 @@  __init int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d)
 		}
 	}
 
-	if (!muxed_banks) {
-		of_node_put(wkup_np);
+	if (!muxed_banks)
 		return 0;
-	}
 
 	irq = irq_of_parse_and_map(wkup_np, 0);
-	of_node_put(wkup_np);
 	if (!irq) {
 		dev_err(dev, "irq number for muxed EINTs not found\n");
 		return 0;
diff --git a/drivers/pinctrl/samsung/pinctrl-s3c64xx.c b/drivers/pinctrl/samsung/pinctrl-s3c64xx.c
index c5d92db4fdb1..9acf65eb0f5b 100644
--- a/drivers/pinctrl/samsung/pinctrl-s3c64xx.c
+++ b/drivers/pinctrl/samsung/pinctrl-s3c64xx.c
@@ -685,7 +685,7 @@  static const struct of_device_id s3c64xx_eint0_irq_ids[] = {
 static int s3c64xx_eint_eint0_init(struct samsung_pinctrl_drv_data *d)
 {
 	struct device *dev = d->dev;
-	struct device_node *eint0_np = NULL;
+	struct device_node *eint0_np __free(device_node) = NULL;
 	struct device_node *np;
 	struct samsung_pin_bank *bank;
 	struct s3c64xx_eint0_data *data;
@@ -701,10 +701,8 @@  static int s3c64xx_eint_eint0_init(struct samsung_pinctrl_drv_data *d)
 		return -ENODEV;
 
 	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
-	if (!data) {
-		of_node_put(eint0_np);
+	if (!data)
 		return -ENOMEM;
-	}
 	data->drvdata = d;
 
 	for (i = 0; i < NUM_EINT0_IRQ; ++i) {
@@ -713,7 +711,6 @@  static int s3c64xx_eint_eint0_init(struct samsung_pinctrl_drv_data *d)
 		irq = irq_of_parse_and_map(eint0_np, i);
 		if (!irq) {
 			dev_err(dev, "failed to get wakeup EINT IRQ %d\n", i);
-			of_node_put(eint0_np);
 			return -ENXIO;
 		}
 
@@ -721,7 +718,6 @@  static int s3c64xx_eint_eint0_init(struct samsung_pinctrl_drv_data *d)
 						 s3c64xx_eint0_handlers[i],
 						 data);
 	}
-	of_node_put(eint0_np);
 
 	bank = d->pin_banks;
 	for (i = 0; i < d->nr_banks; ++i, ++bank) {
diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c
index ed07e23e0912..4cae112ca15b 100644
--- a/drivers/pinctrl/samsung/pinctrl-samsung.c
+++ b/drivers/pinctrl/samsung/pinctrl-samsung.c
@@ -250,7 +250,6 @@  static int samsung_dt_node_to_map(struct pinctrl_dev *pctldev,
 {
 	struct samsung_pinctrl_drv_data *drvdata;
 	unsigned reserved_maps;
-	struct device_node *np;
 	int ret;
 
 	drvdata = pinctrl_dev_get_drvdata(pctldev);
@@ -265,12 +264,11 @@  static int samsung_dt_node_to_map(struct pinctrl_dev *pctldev,
 							&reserved_maps,
 							num_maps);
 
-	for_each_child_of_node(np_config, np) {
+	for_each_child_of_node_scoped(np_config, np) {
 		ret = samsung_dt_subnode_to_map(drvdata, pctldev->dev, np, map,
 						&reserved_maps, num_maps);
 		if (ret < 0) {
 			samsung_dt_free_map(pctldev, *map, *num_maps);
-			of_node_put(np);
 			return ret;
 		}
 	}
@@ -753,7 +751,6 @@  static struct samsung_pmx_func *samsung_pinctrl_create_functions(
 {
 	struct samsung_pmx_func *functions, *func;
 	struct device_node *dev_np = dev->of_node;
-	struct device_node *cfg_np;
 	unsigned int func_cnt = 0;
 	int ret;
 
@@ -761,9 +758,7 @@  static struct samsung_pmx_func *samsung_pinctrl_create_functions(
 	 * Iterate over all the child nodes of the pin controller node
 	 * and create pin groups and pin function lists.
 	 */
-	for_each_child_of_node(dev_np, cfg_np) {
-		struct device_node *func_np;
-
+	for_each_child_of_node_scoped(dev_np, cfg_np) {
 		if (!of_get_child_count(cfg_np)) {
 			if (!of_find_property(cfg_np,
 			    "samsung,pin-function", NULL))
@@ -772,7 +767,7 @@  static struct samsung_pmx_func *samsung_pinctrl_create_functions(
 			continue;
 		}
 
-		for_each_child_of_node(cfg_np, func_np) {
+		for_each_child_of_node_scoped(cfg_np, func_np) {
 			if (!of_find_property(func_np,
 			    "samsung,pin-function", NULL))
 				continue;
@@ -791,16 +786,12 @@  static struct samsung_pmx_func *samsung_pinctrl_create_functions(
 	 * and create pin groups and pin function lists.
 	 */
 	func_cnt = 0;
-	for_each_child_of_node(dev_np, cfg_np) {
-		struct device_node *func_np;
-
+	for_each_child_of_node_scoped(dev_np, cfg_np) {
 		if (!of_get_child_count(cfg_np)) {
 			ret = samsung_pinctrl_create_function(dev, drvdata,
 							cfg_np, func);
-			if (ret < 0) {
-				of_node_put(cfg_np);
+			if (ret < 0)
 				return ERR_PTR(ret);
-			}
 			if (ret > 0) {
 				++func;
 				++func_cnt;
@@ -808,14 +799,11 @@  static struct samsung_pmx_func *samsung_pinctrl_create_functions(
 			continue;
 		}
 
-		for_each_child_of_node(cfg_np, func_np) {
+		for_each_child_of_node_scoped(cfg_np, func_np) {
 			ret = samsung_pinctrl_create_function(dev, drvdata,
 						func_np, func);
-			if (ret < 0) {
-				of_node_put(func_np);
-				of_node_put(cfg_np);
+			if (ret < 0)
 				return ERR_PTR(ret);
-			}
 			if (ret > 0) {
 				++func;
 				++func_cnt;