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


Groups > linux.kernel > #1544329 > unrolled thread

[RFC] Question about freeing of resource in 'atlas7_pinmux_probe()', in file 'drivers/pinctrl/sirf/pinctrl-atlas7.c'

Started byMarion & Christophe JAILLET <christophe.jaillet@wanadoo.fr>
First post2016-12-19 07:30 +0100
Last post2016-12-20 06:50 +0100
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [RFC] Question about freeing of resource in 'atlas7_pinmux_probe()',  in file 'drivers/pinctrl/sirf/pinctrl-atlas7.c' Marion & Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2016-12-19 07:30 +0100
    Re: [RFC] Question about freeing of resource in  'atlas7_pinmux_probe()', in file 'drivers/pinctrl/sirf/pinctrl-atlas7.c' Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com> - 2016-12-19 15:00 +0100
      Re: [RFC] Question about freeing of resource in  'atlas7_pinmux_probe()', in file 'drivers/pinctrl/sirf/pinctrl-atlas7.c' Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2016-12-20 06:50 +0100

#1544329 — [RFC] Question about freeing of resource in 'atlas7_pinmux_probe()', in file 'drivers/pinctrl/sirf/pinctrl-atlas7.c'

FromMarion & Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Date2016-12-19 07:30 +0100
Subject[RFC] Question about freeing of resource in 'atlas7_pinmux_probe()', in file 'drivers/pinctrl/sirf/pinctrl-atlas7.c'
Message-ID<sPZCp-49P-3@gated-at.bofh.it>
Hi,

while playing with coccinelle, a missing 'of_node_put()' triggered in 
'atlas7_pinmux_probe()', in file 'drivers/pinctrl/sirf/pinctrl-atlas7.c'.

     /* The sd3 and sd9 shared all pins, and the function select by
      * SYS2PCI_SDIO9SEL register
      */
     sys2pci_np = of_find_node_by_name(NULL, "sys2pci");
     if (!sys2pci_np)
         return -EINVAL;
     ret = of_address_to_resource(sys2pci_np, 0, &res);
     if (ret) <-------------    missing of_node_put(sys2pci_np);
         return ret;
     pmx->sys2pci_base = devm_ioremap_resource(&pdev->dev, &res);
     if (IS_ERR(pmx->sys2pci_base)) {
         of_node_put(sys2pci_np); <-------------    added by commit 
151b8c5ba1eb
         return -ENOMEM;
     }

Looking at the history of this file, I found a recent commit that added 
another missing of_node_put (see above).


Adding missing 'of_node_put()' in error handling paths is fine, but in 
this particular case, I was wondering if one was not also missing in the 
normal path?


In such a case, I would revert 151b8c5ba1eb and propose something like:
     /* The sd3 and sd9 shared all pins, and the function select by
      * SYS2PCI_SDIO9SEL register
      */
     sys2pci_np = of_find_node_by_name(NULL, "sys2pci");
     if (!sys2pci_np)
         return -EINVAL;
     ret = of_address_to_resource(sys2pci_np, 0, &res);
     if (ret) {
         of_node_put(sys2pci_np);
         return ret;
     }
     of_node_put(sys2pci_np);

     pmx->sys2pci_base = devm_ioremap_resource(&pdev->dev, &res);
     if (IS_ERR(pmx->sys2pci_base))
         return -ENOMEM;

Thanks for your comment,

best regards,

CJ

[toc] | [next] | [standalone]


#1544539 — Re: [RFC] Question about freeing of resource in 'atlas7_pinmux_probe()', in file 'drivers/pinctrl/sirf/pinctrl-atlas7.c'

FromVladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
Date2016-12-19 15:00 +0100
SubjectRe: [RFC] Question about freeing of resource in 'atlas7_pinmux_probe()', in file 'drivers/pinctrl/sirf/pinctrl-atlas7.c'
Message-ID<sQ6DU-8us-35@gated-at.bofh.it>
In reply to#1544329
Hi,

On 12/19/2016 08:19 AM, Marion & Christophe JAILLET wrote:
> Hi,
> 
> while playing with coccinelle, a missing 'of_node_put()' triggered in 
> 'atlas7_pinmux_probe()', in file 'drivers/pinctrl/sirf/pinctrl-atlas7.c'.
> 
>      /* The sd3 and sd9 shared all pins, and the function select by
>       * SYS2PCI_SDIO9SEL register
>       */
>      sys2pci_np = of_find_node_by_name(NULL, "sys2pci");
>      if (!sys2pci_np)
>          return -EINVAL;
>      ret = of_address_to_resource(sys2pci_np, 0, &res);
>      if (ret) <-------------    missing of_node_put(sys2pci_np);
>          return ret;
>      pmx->sys2pci_base = devm_ioremap_resource(&pdev->dev, &res);
>      if (IS_ERR(pmx->sys2pci_base)) {
>          of_node_put(sys2pci_np); <-------------    added by commit 
> 151b8c5ba1eb
>          return -ENOMEM;
>      }
> 
> Looking at the history of this file, I found a recent commit that added 
> another missing of_node_put (see above).
> 
> 
> Adding missing 'of_node_put()' in error handling paths is fine, but in 
> this particular case, I was wondering if one was not also missing in the 
> normal path?

Right, in this particular case 'of_node_put()' should be both on error
and normal paths.

> 
> In such a case, I would revert 151b8c5ba1eb and propose something like:
>      /* The sd3 and sd9 shared all pins, and the function select by
>       * SYS2PCI_SDIO9SEL register
>       */
>      sys2pci_np = of_find_node_by_name(NULL, "sys2pci");
>      if (!sys2pci_np)
>          return -EINVAL;
>      ret = of_address_to_resource(sys2pci_np, 0, &res);
>      if (ret) {
>          of_node_put(sys2pci_np);
>          return ret;
>      }
>      of_node_put(sys2pci_np);

Functionally it looks good, I have two comments though.

1) you don't need to revert 151b8c5ba1eb, the commit is a proper fix
   per se but incomplete, please add your change on top of it,

2) minimizing the lines of code by removing duplicates is always good,
   so here a better and complete fix will be like the following one:

	sys2pci_np = of_find_node_by_name(NULL, "sys2pci");
	if (!sys2pci_np)
		return -EINVAL;

	ret = of_address_to_resource(sys2pci_np, 0, &res);
	of_node_put(sys2pci_np);
	if (ret)
		return ret;

	pmx->sys2pci_base = devm_ioremap_resource(&pdev->dev, &res);
	if (IS_ERR(pmx->sys2pci_base))
		return -ENOMEM;

> 
>      pmx->sys2pci_base = devm_ioremap_resource(&pdev->dev, &res);
>      if (IS_ERR(pmx->sys2pci_base))
>          return -ENOMEM;

--
With best wishes,
Vladimir

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


#1544907 — Re: [RFC] Question about freeing of resource in 'atlas7_pinmux_probe()', in file 'drivers/pinctrl/sirf/pinctrl-atlas7.c'

FromChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Date2016-12-20 06:50 +0100
SubjectRe: [RFC] Question about freeing of resource in 'atlas7_pinmux_probe()', in file 'drivers/pinctrl/sirf/pinctrl-atlas7.c'
Message-ID<sQltf-1oo-5@gated-at.bofh.it>
In reply to#1544539
Le 19/12/2016 à 14:54, Vladimir Zapolskiy a écrit :
> Functionally it looks good, I have two comments though.
> 1) you don't need to revert 151b8c5ba1eb, the commit is a proper fix
>     per se but incomplete, please add your change on top of it,
>
> 2) minimizing the lines of code by removing duplicates is always good,
>     so here a better and complete fix will be like the following one:
>
Hi,

thanks for the feedback and comments.
Patch submitted.

CJ

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web