public inbox for linux-s390@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] s390/ap: fix memory leak in ap_init_qci_info()
@ 2022-11-14 11:08 Wei Yongjun
  2022-11-15  9:45 ` Harald Freudenberger
  0 siblings, 1 reply; 2+ messages in thread
From: Wei Yongjun @ 2022-11-14 11:08 UTC (permalink / raw)
  To: Harald Freudenberger, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger, Sven Schnelle,
	Tony Krowiak
  Cc: Wei Yongjun, linux-s390

From: Wei Yongjun <weiyongjun1@huawei.com>

If kzalloc() for 'ap_qci_info_old' failed, 'ap_qci_info' shold be
freed before return. Otherwise it is a memory leak.

Fixes: 283915850a44 ("s390/ap: notify drivers on config changed and scan complete callbacks")
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
 drivers/s390/crypto/ap_bus.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/s390/crypto/ap_bus.c b/drivers/s390/crypto/ap_bus.c
index 59ac98f2bd27..6cbc5e5d2a0e 100644
--- a/drivers/s390/crypto/ap_bus.c
+++ b/drivers/s390/crypto/ap_bus.c
@@ -233,8 +233,10 @@ static void __init ap_init_qci_info(void)
 	if (!ap_qci_info)
 		return;
 	ap_qci_info_old = kzalloc(sizeof(*ap_qci_info_old), GFP_KERNEL);
-	if (!ap_qci_info_old)
+	if (!ap_qci_info_old) {
+		kfree(ap_qci_info);
 		return;
+	}
 	if (ap_fetch_qci_info(ap_qci_info) != 0) {
 		kfree(ap_qci_info);
 		kfree(ap_qci_info_old);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] s390/ap: fix memory leak in ap_init_qci_info()
  2022-11-14 11:08 [PATCH] s390/ap: fix memory leak in ap_init_qci_info() Wei Yongjun
@ 2022-11-15  9:45 ` Harald Freudenberger
  0 siblings, 0 replies; 2+ messages in thread
From: Harald Freudenberger @ 2022-11-15  9:45 UTC (permalink / raw)
  To: Wei Yongjun
  Cc: Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
	Christian Borntraeger, Sven Schnelle, Tony Krowiak, Wei Yongjun,
	linux-s390

On 2022-11-14 12:08, Wei Yongjun wrote:
> From: Wei Yongjun <weiyongjun1@huawei.com>
> 
> If kzalloc() for 'ap_qci_info_old' failed, 'ap_qci_info' shold be
> freed before return. Otherwise it is a memory leak.
> 
> Fixes: 283915850a44 ("s390/ap: notify drivers on config changed and
> scan complete callbacks")
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> ---
>  drivers/s390/crypto/ap_bus.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/s390/crypto/ap_bus.c 
> b/drivers/s390/crypto/ap_bus.c
> index 59ac98f2bd27..6cbc5e5d2a0e 100644
> --- a/drivers/s390/crypto/ap_bus.c
> +++ b/drivers/s390/crypto/ap_bus.c
> @@ -233,8 +233,10 @@ static void __init ap_init_qci_info(void)
>  	if (!ap_qci_info)
>  		return;
>  	ap_qci_info_old = kzalloc(sizeof(*ap_qci_info_old), GFP_KERNEL);
> -	if (!ap_qci_info_old)
> +	if (!ap_qci_info_old) {
> +		kfree(ap_qci_info);
>  		return;
> +	}
>  	if (ap_fetch_qci_info(ap_qci_info) != 0) {
>  		kfree(ap_qci_info);
>  		kfree(ap_qci_info_old);
Thanks, I picked this and pushed it into the s390 subsystem repo.
Will be visible in the Linus' tree with the next merge window.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-15  9:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-14 11:08 [PATCH] s390/ap: fix memory leak in ap_init_qci_info() Wei Yongjun
2022-11-15  9:45 ` Harald Freudenberger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox