Skip to content
/ linux Public

Commit d282757

Browse files
outman119gregkh
authored andcommitted
firmware: arm_scpi: Fix device_node reference leak in probe path
[ Upstream commit 879c001 ] A device_node reference obtained from the device tree is not released on all error paths in the arm_scpi probe path. Specifically, a node returned by of_parse_phandle() could be leaked when the probe failed after the node was acquired. The probe function returns early and the shmem reference is not released. Use __free(device_node) scope-based cleanup to automatically release the reference when the variable goes out of scope. Fixes: ed7ecb8 ("firmware: arm_scpi: Add compatibility checks for shmem node") Signed-off-by: Felix Gu <ustc.gu@gmail.com> Message-Id: <20260121-arm_scpi_2-v2-1-702d7fa84acb@gmail.com> Signed-off-by: Sudeep Holla <sudeep.holla@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 3983811 commit d282757

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/firmware/arm_scpi.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <linux/bitmap.h>
2020
#include <linux/bitfield.h>
21+
#include <linux/cleanup.h>
2122
#include <linux/device.h>
2223
#include <linux/err.h>
2324
#include <linux/export.h>
@@ -940,13 +941,13 @@ static int scpi_probe(struct platform_device *pdev)
940941
int idx = scpi_drvinfo->num_chans;
941942
struct scpi_chan *pchan = scpi_drvinfo->channels + idx;
942943
struct mbox_client *cl = &pchan->cl;
943-
struct device_node *shmem = of_parse_phandle(np, "shmem", idx);
944+
struct device_node *shmem __free(device_node) =
945+
of_parse_phandle(np, "shmem", idx);
944946

945947
if (!of_match_node(shmem_of_match, shmem))
946948
return -ENXIO;
947949

948950
ret = of_address_to_resource(shmem, 0, &res);
949-
of_node_put(shmem);
950951
if (ret) {
951952
dev_err(dev, "failed to get SCPI payload mem resource\n");
952953
return ret;

0 commit comments

Comments
 (0)