1 From 8aa0fec4331ad11030cfc43ddd16b42dd759dfc2 Mon Sep 17 00:00:00 2001
2 From: Peng Hao <peng.hao2@zte.com.cn>
3 Date: Tue, 2 Apr 2019 22:12:38 +0800
4 Subject: arm/mach-at91/pm : fix possible object reference leak
6 [ Upstream commit ba5e60c9b75dec92d4c695b928f69300b17d7686 ]
8 of_find_device_by_node() takes a reference to the struct device
9 when it finds a match via get_device. When returning error we should
12 Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>
13 Signed-off-by: Peng Hao <peng.hao2@zte.com.cn>
14 Signed-off-by: Ludovic Desroches <ludovic.desroches@microchip.com>
15 Signed-off-by: Sasha Levin (Microsoft) <sashal@kernel.org>
17 arch/arm/mach-at91/pm.c | 6 ++++--
18 1 file changed, 4 insertions(+), 2 deletions(-)
20 diff --git a/arch/arm/mach-at91/pm.c b/arch/arm/mach-at91/pm.c
21 index 51e808adb00c..2a757dcaa1a5 100644
22 --- a/arch/arm/mach-at91/pm.c
23 +++ b/arch/arm/mach-at91/pm.c
24 @@ -591,13 +591,13 @@ static int __init at91_pm_backup_init(void)
26 np = of_find_compatible_node(NULL, NULL, "atmel,sama5d2-securam");
29 + goto securam_fail_no_ref_dev;
31 pdev = of_find_device_by_node(np);
34 pr_warn("%s: failed to find securam device!\n", __func__);
36 + goto securam_fail_no_ref_dev;
39 sram_pool = gen_pool_get(&pdev->dev, NULL);
40 @@ -620,6 +620,8 @@ static int __init at91_pm_backup_init(void)
44 + put_device(&pdev->dev);
45 +securam_fail_no_ref_dev:
46 iounmap(pm_data.sfrbu);