Skip to contentSkip to conversation

firmware: arm_scmi: Avoid leak OF node on error

PATCH NAK [email protected] 3 participants 3 messages May 23, 2022 System control & power/management interface (SCPI/SCMI) Message Protocol drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 firmware: arm_scmi: Avoid leak OF node on error

From: Minghao Chi <[email protected]>

The OF node should be put before returning error in smc_chan_available(), otherwise node's refcount will be leaked.

---
 drivers/firmware/arm_scmi/smc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/arm_scmi/smc.c +1 -1
index 745acfdd0b3d..43018be70edc 100644
@@ -55,10 +55,10 @@ static irqreturn_t smc_msg_done_isr(int irq, void *data)
 static bool smc_chan_available(struct device *dev, int idx)
 {
 	struct device_node *np = of_parse_phandle(dev->of_node, "shmem", 0);
+	of_node_put(np);
 	if (!np)
 		return false;
 
-	of_node_put(np);
 	return true;
 }
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 16 lines · On Mon, May 23, 2022 at 11:11:16AM +0000, [email protected] wrote:

From: Minghao Chi <[email protected]>

The OF node should be put before returning error in smc_chan_available(), otherwise node's refcount will be leaked.

---
 drivers/firmware/arm_scmi/smc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/arm_scmi/smc.c +0 -0
index 745acfdd0b3d..43018be70edc 100644

drivers/firmware/arm_scmi/smc.c static irqreturn_t smc_msg_done_isr(int irq, void *data) · line 63

Quoted 10 lines
drivers/firmware/arm_scmi/smc.c +1 -1
@@ -55,10 +55,10 @@ static irqreturn_t smc_msg_done_isr(int irq, void *data)
 static bool smc_chan_available(struct device *dev, int idx)
 {
 	struct device_node *np = of_parse_phandle(dev->of_node, "shmem", 0);
+	of_node_put(np);
 	if (!np)
 		return false;
 
-	of_node_put(np);
 	return true;
 }

NAK

#2 lore raw
In reply to [email protected]
Quoted 16 lines · On Mon, May 23, 2022 at 11:11:16AM +0000, [email protected] wrote:

From: Minghao Chi <[email protected]>

The OF node should be put before returning error in smc_chan_available(), otherwise node's refcount will be leaked.

---
 drivers/firmware/arm_scmi/smc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/arm_scmi/smc.c +0 -0
index 745acfdd0b3d..43018be70edc 100644

drivers/firmware/arm_scmi/smc.c static irqreturn_t smc_msg_done_isr(int irq, void *data) · line 58

Quoted 4 lines
drivers/firmware/arm_scmi/smc.c +1 -0
@@ -55,10 +55,10 @@ static irqreturn_t smc_msg_done_isr(int irq, void *data)
 static bool smc_chan_available(struct device *dev, int idx)
 {
 	struct device_node *np = of_parse_phandle(dev->of_node, "shmem", 0);
+	of_node_put(np);

While this may work as of_node_put handles NULL as argument, what is the point of unnecessary of_node_put(NULL) here ?

Signature · 2 lines
Regards,
Sudeep