Skip to content

Commit

Permalink
ata: libahci_platform: Add of_node_put() before loop exit
Browse files Browse the repository at this point in the history
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.

Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Nishka Dasgupta authored and Jens Axboe committed Sep 19, 2019
1 parent 8454d68 commit d7f76f3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions drivers/ata/libahci_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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++;
}
Expand Down

0 comments on commit d7f76f3

Please sign in to comment.