2022-11-14 11:18:45

by Wei Yongjun

[permalink] [raw]
Subject: [PATCH] irqchip/wpcm450: fix memory leak in ap_init_qci_info()

From: Wei Yongjun <[email protected]>

If of_iomap() failed, 'aic' should be freed before return. Otherwise
there is a memory leak.

Fixes: fead4dd49663 ("irqchip: Add driver for WPCM450 interrupt controller")
Signed-off-by: Wei Yongjun <[email protected]>
---
drivers/irqchip/irq-wpcm450-aic.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/irqchip/irq-wpcm450-aic.c b/drivers/irqchip/irq-wpcm450-aic.c
index 0dcbeb1a05a1..91df62a64cd9 100644
--- a/drivers/irqchip/irq-wpcm450-aic.c
+++ b/drivers/irqchip/irq-wpcm450-aic.c
@@ -146,6 +146,7 @@ static int __init wpcm450_aic_of_init(struct device_node *node,
aic->regs = of_iomap(node, 0);
if (!aic->regs) {
pr_err("Failed to map WPCM450 AIC registers\n");
+ kfree(aic);
return -ENOMEM;
}

--
2.34.1



2022-11-15 09:31:57

by Jonathan Neuschäfer

[permalink] [raw]
Subject: Re: [PATCH] irqchip/wpcm450: fix memory leak in ap_init_qci_info()

Hi,

the function name is wrong in the in the subject line. Other than that,
the patch looks good.

Thanks,
Jonathan


On Mon, Nov 14, 2022 at 11:08:54AM +0000, Wei Yongjun wrote:
> From: Wei Yongjun <[email protected]>
>
> If of_iomap() failed, 'aic' should be freed before return. Otherwise
> there is a memory leak.
>
> Fixes: fead4dd49663 ("irqchip: Add driver for WPCM450 interrupt controller")
> Signed-off-by: Wei Yongjun <[email protected]>
> ---
> drivers/irqchip/irq-wpcm450-aic.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/irqchip/irq-wpcm450-aic.c b/drivers/irqchip/irq-wpcm450-aic.c
> index 0dcbeb1a05a1..91df62a64cd9 100644
> --- a/drivers/irqchip/irq-wpcm450-aic.c
> +++ b/drivers/irqchip/irq-wpcm450-aic.c
> @@ -146,6 +146,7 @@ static int __init wpcm450_aic_of_init(struct device_node *node,
> aic->regs = of_iomap(node, 0);
> if (!aic->regs) {
> pr_err("Failed to map WPCM450 AIC registers\n");
> + kfree(aic);
> return -ENOMEM;
> }
>
> --
> 2.34.1
>


Attachments:
(No filename) (1.03 kB)
signature.asc (849.00 B)
Download all attachments

2022-11-15 09:57:37

by Wei Yongjun

[permalink] [raw]
Subject: Re: [PATCH] irqchip/wpcm450: fix memory leak in ap_init_qci_info()


On 2022/11/15 16:36, Jonathan Neuschäfer wrote:
> Hi,
>
> the function name is wrong in the in the subject line. Other than that,
> the patch looks good.


Thanks, will fix in next version.


Regards,

Wei Yongjun


>
> Thanks,
> Jonathan
>
>
> On Mon, Nov 14, 2022 at 11:08:54AM +0000, Wei Yongjun wrote:
>> From: Wei Yongjun <[email protected]>
>>
>> If of_iomap() failed, 'aic' should be freed before return. Otherwise
>> there is a memory leak.
>>
>> Fixes: fead4dd49663 ("irqchip: Add driver for WPCM450 interrupt controller")
>> Signed-off-by: Wei Yongjun <[email protected]>
>> ---
>> drivers/irqchip/irq-wpcm450-aic.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/irqchip/irq-wpcm450-aic.c b/drivers/irqchip/irq-wpcm450-aic.c
>> index 0dcbeb1a05a1..91df62a64cd9 100644
>> --- a/drivers/irqchip/irq-wpcm450-aic.c
>> +++ b/drivers/irqchip/irq-wpcm450-aic.c
>> @@ -146,6 +146,7 @@ static int __init wpcm450_aic_of_init(struct device_node *node,
>> aic->regs = of_iomap(node, 0);
>> if (!aic->regs) {
>> pr_err("Failed to map WPCM450 AIC registers\n");
>> + kfree(aic);
>> return -ENOMEM;
>> }
>>
>> --
>> 2.34.1
>>