lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Fri, 2 Apr 2021 09:32:01 +0200
From:   Nicolas Ferre <nicolas.ferre@...rochip.com>
To:     Claudiu Beznea - M18063 <Claudiu.Beznea@...rochip.com>,
        "sre@...nel.org" <sre@...nel.org>,
        "alexandre.belloni@...tlin.com" <alexandre.belloni@...tlin.com>,
        Ludovic Desroches - M43218 <Ludovic.Desroches@...rochip.com>
CC:     "linux-pm@...r.kernel.org" <linux-pm@...r.kernel.org>,
        "linux-arm-kernel@...ts.infradead.org" 
        <linux-arm-kernel@...ts.infradead.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        kernel test robot <lkp@...el.com>,
        "Dan Carpenter" <dan.carpenter@...cle.com>
Subject: Re: [PATCH] power: reset: at91-reset: free resources on exit path

On 01/04/2021 at 16:42, Claudiu Beznea - M18063 wrote:
>>> +unmap:
>>> +    iounmap(reset->rstc_base);
>>> +    for (idx = 0; idx < ARRAY_SIZE(reset->ramc_base); idx++)
>>> +        iounmap(reset->ramc_base[idx]);
>> But if we keep this loop, I have the feeling that some kind of
>> "of_node_put()" is needed as well.
> No! In the loop:
> 
> for_each_matching_node_and_match(np, at91_ramc_of_match, &match) {
> 	reset->ramc_lpr = (u32)match->data;
> 	reset->ramc_base[idx] = of_iomap(np, 0);
> 	if (!reset->ramc_base[idx]) {
> 		dev_err(&pdev->dev, "Could not map ram controller address\n");
> 		of_node_put(np);
> 		ret = -ENODEV;
> 		goto unmap;
> 	}
> 	idx++;
> }
> 
> the of_node_put() is needed only if the loop is interrupted as the macro:
> for_each_matching_node_and_match() is defined as follows:
> 
> #define for_each_matching_node_and_match(dn, matches, match) \
> 	for (dn = of_find_matching_node_and_match(NULL, matches, match); \
> 	     dn; dn = of_find_matching_node_and_match(dn, matches, match))
> 
> and of_find_matching_node_and_match() will return a np with refcount
> incremented but at the next loop step the of_find_matching_node_and_match()
> will be called with the same np pointer and the np refcount will be
> decremented.
> 
> struct device_node *of_find_matching_node_and_match(
> 		struct device_node *from,
> 		const struct of_device_id *matches,
> 		const struct of_device_id **match)
> {
> 	// ...
> 	of_node_put(from);
> 	// ...
> }

Oh yes you're right Claudiu, I overlooked this one. Thanks for the 
in-depth explanation.

Best regards,
   Nicolas

-- 
Nicolas Ferre

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ