As the doc of of_parse_phandle() states: "The device_node pointer with refcount incremented. Use * of_node_put() on it when done."
Subsystems (4)
PATCH 1/1 As the doc of of_parse_phandle() states: "The device_node pointer with refcount incremented. Use * of_node_put() on it when done."
The function doesn't callsof_node_put() to release this reference, causing a reference leak.
Move the of_parse_phandle() call after devm_kzalloc() and add the missing of_node_put() call immediately after of_address_to_resource() to properly release the device node reference.
Found via static analysis.
--- drivers/gpu/drm/sysfb/simpledrm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/gpu/drm/sysfb/simpledrm.c +5 -4
@@ -183,15 +183,16 @@ simplefb_get_memory_of(struct drm_device *dev, struct device_node *of_node)struct resource *res;int err; - np =of_parse_phandle (of_node,"memory-region" ,0 ); -if (!np) -return NULL ; - res =devm_kzalloc (dev->dev,sizeof (*res),GFP_KERNEL );if (!res)return ERR_PTR (-ENOMEM ); + np =of_parse_phandle (of_node,"memory-region" ,0 ); +if (!np) +return NULL ; + err =of_address_to_resource (np,0 , res); +of_node_put (np);if (err)return ERR_PTR (err);
Signature · 1 line
2.35.1
Re: [PATCH] As the doc of of_parse_phandle() states: …
Please choose a more appropriate patch subject.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.17-rc4#n638
Quoted 3 lines
Move the
of_parse_phandle()call afterdevm_kzalloc()and add the missingof_node_put()call immediately afterof_address_to_resource()to properly release the device node reference.
How do you think about to increase the application of scope-based resource management?
https://elixir.bootlin.com/linux/v6.17-rc4/source/include/linux/of.h#L138
Quoted 1 line
Found via static analysis.
Which concrete software tools would be involved for this purpose?
Regards,
Markus