lkml.org 
[lkml]   [2019]   [Aug]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] ata: libahci_platform: Add of_node_put() before loop exit
From
Date
Hi,

On 15-08-19 08:00, Nishka Dasgupta wrote:
> Each iteration of for_each_child_of_node puts the previous node, but
> in the case of a goto from the middle of the loop, there is no put,
> thus causing a memory leak. Add an of_node_put before three such goto
> statements.
> Issue found with Coccinelle.
>
> Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>

I really believe the for_each_child_of_node semantics are broken, see my
other reply. But that is no reason not to fix this, so this is:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans


> ---
> drivers/ata/libahci_platform.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c
> index 9e9583a6bba9..e742780950de 100644
> --- a/drivers/ata/libahci_platform.c
> +++ b/drivers/ata/libahci_platform.c
> @@ -497,6 +497,7 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,
>
> if (of_property_read_u32(child, "reg", &port)) {
> rc = -EINVAL;
> + of_node_put(child);
> goto err_out;
> }
>
> @@ -514,14 +515,18 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,
> if (port_dev) {
> rc = ahci_platform_get_regulator(hpriv, port,
> &port_dev->dev);
> - if (rc == -EPROBE_DEFER)
> + if (rc == -EPROBE_DEFER) {
> + of_node_put(child);
> goto err_out;
> + }
> }
> #endif
>
> rc = ahci_platform_get_phy(hpriv, port, dev, child);
> - if (rc)
> + if (rc) {
> + of_node_put(child);
> goto err_out;
> + }
>
> enabled_ports++;
> }
>

\
 
 \ /
  Last update: 2019-08-15 10:57    [W:0.090 / U:0.448 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site