Skip to content

Commit

Permalink
arm/xen: Fix some refcount leaks
Browse files Browse the repository at this point in the history
[ Upstream commit 533bec1 ]

The of_find_compatible_node() function returns a node pointer with
refcount incremented, We should use of_node_put() on it when done
Add the missing of_node_put() to release the refcount.

Fixes: 9b08aaa ("ARM: XEN: Move xen_early_init() before efi_init()")
Fixes: b237158 ("arm/xen: Read extended regions from DT and init Xen resource")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Yuuoniy authored and gregkh committed Apr 27, 2022
1 parent 9b6308d commit bbcd026
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions arch/arm/xen/enlighten.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,15 @@ int __init arch_xen_unpopulated_init(struct resource **res)

if (!nr_reg) {
pr_err("No extended regions are found\n");
of_node_put(np);
return -EINVAL;
}

regs = kcalloc(nr_reg, sizeof(*regs), GFP_KERNEL);
if (!regs)
if (!regs) {
of_node_put(np);
return -ENOMEM;
}

/*
* Create resource from extended regions provided by the hypervisor to be
Expand Down Expand Up @@ -403,8 +406,8 @@ int __init arch_xen_unpopulated_init(struct resource **res)
*res = &xen_resource;

err:
of_node_put(np);
kfree(regs);

return rc;
}
#endif
Expand All @@ -424,8 +427,10 @@ static void __init xen_dt_guest_init(void)

if (of_address_to_resource(xen_node, GRANT_TABLE_INDEX, &res)) {
pr_err("Xen grant table region is not found\n");
of_node_put(xen_node);
return;
}
of_node_put(xen_node);
xen_grant_frames = res.start;
}

Expand Down

0 comments on commit bbcd026

Please sign in to comment.