All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] firmware: arm_scmi: fix an OF node reference leak in scmi_txrx_setup()
@ 2024-12-17  2:31 Joe Hattori
  2024-12-17  5:51 ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Joe Hattori @ 2024-12-17  2:31 UTC (permalink / raw)
  To: sudeep.holla, cristian.marussi; +Cc: arm-scmi, Joe Hattori

scmi_txrx_setup() calls scmi_chan_setup(), which increments the refcount
of the given OF node. When the Rx channel setup fails with ENOMEM,
scmi_chan_setup() returns the error, but does not release the OF node
obtained in the Tx channel setup. Thus, add an of_node_put() call when
the Rx setup fails with ENOMEM.

This bug was found by an experimental static analysis tool that I am
developing.

Fixes: be9ba1f7f9e0 ("firmware: arm_scmi: Make Rx chan_setup fail on memory errors")
Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
---
 drivers/firmware/arm_scmi/driver.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index 1b5fb2c4ce86..5d8f877d75f3 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -2700,7 +2700,9 @@ scmi_txrx_setup(struct scmi_info *info, struct device_node *of_node,
 	if (!ret) {
 		/* Rx is optional, report only memory errors */
 		ret = scmi_chan_setup(info, of_node, prot_id, false);
-		if (ret && ret != -ENOMEM)
+		if (ret == -ENOMEM)
+			of_node_put(of_node);
+		else if (ret)
 			ret = 0;
 	}
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-12-17 14:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-17  2:31 [PATCH] firmware: arm_scmi: fix an OF node reference leak in scmi_txrx_setup() Joe Hattori
2024-12-17  5:51 ` Dan Carpenter
2024-12-17 10:50   ` Krzysztof Kozlowski
2024-12-17 14:27     ` Sudeep Holla

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.