Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ata: libahci_platform: Add of_node_put() before loop exit

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>

authored by

Nishka Dasgupta and committed by
Jens Axboe
d7f76f36 8454d685

+7 -2
+7 -2
drivers/ata/libahci_platform.c
··· 497 497 498 498 if (of_property_read_u32(child, "reg", &port)) { 499 499 rc = -EINVAL; 500 + of_node_put(child); 500 501 goto err_out; 501 502 } 502 503 ··· 515 514 if (port_dev) { 516 515 rc = ahci_platform_get_regulator(hpriv, port, 517 516 &port_dev->dev); 518 - if (rc == -EPROBE_DEFER) 517 + if (rc == -EPROBE_DEFER) { 518 + of_node_put(child); 519 519 goto err_out; 520 + } 520 521 } 521 522 #endif 522 523 523 524 rc = ahci_platform_get_phy(hpriv, port, dev, child); 524 - if (rc) 525 + if (rc) { 526 + of_node_put(child); 525 527 goto err_out; 528 + } 526 529 527 530 enabled_ports++; 528 531 }