From: julia.lawall@lip6.fr (Julia Lawall)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/9] pci: mvebu: fix memory leaks and refcount leaks
Date: Fri, 9 Oct 2015 18:39:47 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.2.10.1510091838440.2665@hadrien> (raw)
In-Reply-To: <20151009153543.GX32532@n2100.arm.linux.org.uk>
On Fri, 9 Oct 2015, Russell King - ARM Linux wrote:
> On Fri, Oct 09, 2015 at 05:14:42PM +0200, Thomas Petazzoni wrote:
> > Julia: some of the Device Tree iterator functions have a somewhat
> > "interesting" behavior in that they take the reference on the current
> > child when entering the loop, and release it before entering the next
> > iteration (which will also take a reference to the next child).
> >
> > This means that if you have an exit point inside the loop (break or
> > return), you are loosing a reference. For example,
> > http://lxr.free-electrons.com/source/arch/arm/mach-shmobile/pm-rmobile.c#L367
> > is wrong because there is a missing of_node_put(np) before the "return
> > -ENOMEM".
> >
> > So essentially, every exit point in such Device Tree iteration loops
> > should make to call of_node_put() on the current element before exiting
> > the loop unexpectedly.
>
> There is an exception to that... if the loop is part of a DT node lookup
> function, which would return a DT node based on some search criteria, it
> would be valid to break out of the loop while holding a reference.
>
> For example, of_get_child_by_name(), of_find_next_cache_node(),
> of_graph_get_port_by_id(), are valid breaker-outer cases. ;)
>
> However, of_platform_bus_probe(), of_platform_populate(),
> of_overlay_apply_one(), overlay_subtree_check() are examples of
> incorrect break-out cases.
Thanks for the examples.
I guess that this incorrect too, for the opposite reason (double put)?
drivers/clk/tegra/clk-emc.c:
for_each_child_of_node(np, node) {
err = of_property_read_u32(node, "nvidia,ram-code",
&node_ram_code);
if (err) {
of_node_put(node);
continue;
}
julia
next prev parent reply other threads:[~2015-10-09 16:39 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-03 18:12 [PATCH 0/9] Further mvebu PCIe patches Russell King - ARM Linux
2015-10-03 18:12 ` [PATCH 1/9] pci: mvebu: move port parsing and resource claiming to separate function Russell King
2015-10-03 18:13 ` [PATCH 2/9] pci: mvebu: fix memory leaks and refcount leaks Russell King
2015-10-09 14:52 ` Thomas Petazzoni
2015-10-09 15:07 ` Andrew Lunn
2015-10-09 15:14 ` Thomas Petazzoni
2015-10-09 15:35 ` Russell King - ARM Linux
2015-10-09 16:39 ` Julia Lawall [this message]
2015-10-09 16:49 ` Russell King - ARM Linux
2015-10-09 15:54 ` Julia Lawall
2015-10-09 15:07 ` Russell King - ARM Linux
2015-10-03 18:13 ` [PATCH 3/9] pci: mvebu: split port parsing and resource claiming from port setup Russell King
2015-10-03 18:13 ` [PATCH 4/9] pci: mvebu: use gpio_set_value_cansleep() Russell King
2015-10-03 18:13 ` [PATCH 5/9] pci: mvebu: use devm_kcalloc() to allocate an array Russell King
2015-10-03 18:13 ` [PATCH 6/9] pci: mvebu: use gpio_desc to carry around gpio Russell King
2015-10-03 18:13 ` [PATCH 7/9] pci: mvebu: better implementation of clock/reset handling Russell King
2015-10-03 18:13 ` [PATCH 8/9] pci: mvebu: add PCI Express root complex capability block Russell King
2015-10-03 18:13 ` [PATCH 9/9] pci: mvebu: remove code restricting accesses to slot 0 Russell King
2015-10-03 19:00 ` [PATCH 0/9] Further mvebu PCIe patches Thomas Petazzoni
2015-10-05 21:05 ` Willy Tarreau
2015-10-08 23:19 ` Andrew Lunn
2015-10-09 15:18 ` Thomas Petazzoni
2015-10-09 16:27 ` Bjorn Helgaas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.10.1510091838440.2665@hadrien \
--to=julia.lawall@lip6.fr \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox