[PATCH v2] firmware: arm_scmi: drop OF node reference in setup

Krzysztof Kozlowski posted 1 patch 2 years, 6 months ago
drivers/firmware/arm_scmi/mailbox.c | 4 +++-
drivers/firmware/arm_scmi/smc.c     | 4 +++-
2 files changed, 6 insertions(+), 2 deletions(-)
[PATCH v2] firmware: arm_scmi: drop OF node reference in setup
Posted by Krzysztof Kozlowski 2 years, 6 months ago
The OF node reference obtained from of_parse_phandle() should be dropped
if node is not compatible with arm,scmi-shmem.

Fixes: 507cd4d2c5eb ("firmware: arm_scmi: Add compatibility checks for shmem node")
Cc: <stable@vger.kernel.org>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

---

Changes in v2:
1. Correct also mailbox.c
---
 drivers/firmware/arm_scmi/mailbox.c | 4 +++-
 drivers/firmware/arm_scmi/smc.c     | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/firmware/arm_scmi/mailbox.c b/drivers/firmware/arm_scmi/mailbox.c
index 1efa5e9392c4..19246ed1f01f 100644
--- a/drivers/firmware/arm_scmi/mailbox.c
+++ b/drivers/firmware/arm_scmi/mailbox.c
@@ -166,8 +166,10 @@ static int mailbox_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 		return -ENOMEM;
 
 	shmem = of_parse_phandle(cdev->of_node, "shmem", idx);
-	if (!of_device_is_compatible(shmem, "arm,scmi-shmem"))
+	if (!of_device_is_compatible(shmem, "arm,scmi-shmem")) {
+		of_node_put(shmem);
 		return -ENXIO;
+	}
 
 	ret = of_address_to_resource(shmem, 0, &res);
 	of_node_put(shmem);
diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
index 621c37efe3ec..2d8c510fbf52 100644
--- a/drivers/firmware/arm_scmi/smc.c
+++ b/drivers/firmware/arm_scmi/smc.c
@@ -137,8 +137,10 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 		return -ENOMEM;
 
 	np = of_parse_phandle(cdev->of_node, "shmem", 0);
-	if (!of_device_is_compatible(np, "arm,scmi-shmem"))
+	if (!of_device_is_compatible(np, "arm,scmi-shmem")) {
+		of_node_put(np);
 		return -ENXIO;
+	}
 
 	ret = of_address_to_resource(np, 0, &res);
 	of_node_put(np);
-- 
2.34.1
Re: [PATCH v2] firmware: arm_scmi: drop OF node reference in setup
Posted by Sudeep Holla 2 years, 6 months ago
On Wed, 19 Jul 2023 08:16:52 +0200, Krzysztof Kozlowski wrote:
> The OF node reference obtained from of_parse_phandle() should be dropped
> if node is not compatible with arm,scmi-shmem.
>

Applied to sudeep.holla/linux (for-next/scmi/fixes), thanks!

[1/1] firmware: arm_scmi: drop OF node reference in setup
      https://git.kernel.org/sudeep.holla/c/da042eb4f061
--
Regards,
Sudeep
Re: [PATCH v2] firmware: arm_scmi: drop OF node reference in setup
Posted by Cristian Marussi 2 years, 6 months ago
On Wed, Jul 19, 2023 at 08:16:52AM +0200, Krzysztof Kozlowski wrote:
> The OF node reference obtained from of_parse_phandle() should be dropped
> if node is not compatible with arm,scmi-shmem.
> 
> Fixes: 507cd4d2c5eb ("firmware: arm_scmi: Add compatibility checks for shmem node")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> 
> ---
> 

LGTM.

Reviewed-by: Cristian Marussi <cristian.marussi@arm.com>

Thanks,
Cristian