Skip to content

Commit 78b7413

Browse files
aheevsudeep-holla
authored andcommitted
firmware: arm_scmi: Fix uninitialized pointers with __free attr
Uninitialized pointers with `__free` attribute can cause undefined behaviour as the memory assigned(randomly) to the pointer is freed automatically when the pointer goes out of scope arm doesn't have any bugs related to this as of now, but it is better to initialize and assign pointers with `__free` attr in one statement to ensure proper scope-based cleanup Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Closes: https://lore.kernel.org/all/aPiG_F5EBQUjZqsl@stanley.mountain/ Signed-off-by: Ally Heev <allyheev@gmail.com> Reviewed-by: Cristian Marussi <cristian.marussi@arm.com> Message-Id: <20251105-aheev-uninitialized-free-attr-arm-v1-1-f7b6cb5d3361@gmail.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
1 parent 8f0b4cc commit 78b7413

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

drivers/firmware/arm_scmi/shmem.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ static void __iomem *shmem_setup_iomap(struct scmi_chan_info *cinfo,
196196
struct resource *res,
197197
struct scmi_shmem_io_ops **ops)
198198
{
199-
struct device_node *shmem __free(device_node);
200199
const char *desc = tx ? "Tx" : "Rx";
201200
int ret, idx = tx ? 0 : 1;
202201
struct device *cdev = cinfo->dev;
@@ -205,7 +204,9 @@ static void __iomem *shmem_setup_iomap(struct scmi_chan_info *cinfo,
205204
void __iomem *addr;
206205
u32 reg_io_width;
207206

208-
shmem = of_parse_phandle(cdev->of_node, "shmem", idx);
207+
struct device_node *shmem __free(device_node) = of_parse_phandle(cdev->of_node,
208+
"shmem", idx);
209+
209210
if (!shmem)
210211
return IOMEM_ERR_PTR(-ENODEV);
211212

0 commit comments

Comments
 (0)