linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4] ACPI / APEI: release resources if gen_pool_add fails
@ 2019-07-15  6:58 luanshi
  2019-07-25 12:46 ` James Morse
  2019-08-13 17:16 ` [PATCH v4.1] " Borislav Petkov
  0 siblings, 2 replies; 6+ messages in thread
From: luanshi @ 2019-07-15  6:58 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown
  Cc: James Morse, Tony Luck, Borislav Petkov, linux-acpi

To avoid memory leaks, destroy ghes_estatus_pool and release memory
allocated via vmalloc() on errors in ghes_estatus_pool_init().

Signed-off-by: Liguang Zhang <zhangliguang@linux.alibaba.com>
---
 drivers/acpi/apei/ghes.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
index a66e00f..6d42ae1 100644
--- a/drivers/acpi/apei/ghes.c
+++ b/drivers/acpi/apei/ghes.c
@@ -153,10 +153,11 @@ static void ghes_unmap(void __iomem *vaddr, enum fixed_addresses fixmap_idx)
 int ghes_estatus_pool_init(int num_ghes)
 {
 	unsigned long addr, len;
+	int rc = 0;
 
 	ghes_estatus_pool = gen_pool_create(GHES_ESTATUS_POOL_MIN_ALLOC_ORDER, -1);
 	if (!ghes_estatus_pool)
-		return -ENOMEM;
+		goto nomem;
 
 	len = GHES_ESTATUS_CACHE_AVG_SIZE * GHES_ESTATUS_CACHE_ALLOCED_MAX;
 	len += (num_ghes * GHES_ESOURCE_PREALLOC_MAX_SIZE);
@@ -164,7 +165,7 @@ int ghes_estatus_pool_init(int num_ghes)
 	ghes_estatus_pool_size_request = PAGE_ALIGN(len);
 	addr = (unsigned long)vmalloc(PAGE_ALIGN(len));
 	if (!addr)
-		return -ENOMEM;
+		goto pool_destroy;
 
 	/*
 	 * New allocation must be visible in all pgd before it can be found by
@@ -172,7 +173,17 @@ int ghes_estatus_pool_init(int num_ghes)
 	 */
 	vmalloc_sync_all();
 
-	return gen_pool_add(ghes_estatus_pool, addr, PAGE_ALIGN(len), -1);
+	rc = gen_pool_add(ghes_estatus_pool, addr, PAGE_ALIGN(len), -1);
+	if (rc)
+		goto pool_destroy;
+	return 0;
+
+pool_destroy:
+	gen_pool_destroy(ghes_estatus_pool);
+	if (addr)
+		vfree((void *)addr);
+nomem:
+	return -ENOMEM;
 }
 
 static int map_gen_v2(struct ghes *ghes)
-- 
1.8.3.1


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

* Re: [PATCH v4] ACPI / APEI: release resources if gen_pool_add fails
  2019-07-15  6:58 [PATCH v4] ACPI / APEI: release resources if gen_pool_add fails luanshi
@ 2019-07-25 12:46 ` James Morse
  2019-07-26  9:29   ` 乱石
  2019-08-13 17:16 ` [PATCH v4.1] " Borislav Petkov
  1 sibling, 1 reply; 6+ messages in thread
From: James Morse @ 2019-07-25 12:46 UTC (permalink / raw)
  To: luanshi
  Cc: Rafael J. Wysocki, Len Brown, Tony Luck, Borislav Petkov, linux-acpi

Hi Liguang,

On 15/07/2019 07:58, luanshi wrote:
> To avoid memory leaks, destroy ghes_estatus_pool and release memory
> allocated via vmalloc() on errors in ghes_estatus_pool_init().
> 
> Signed-off-by: Liguang Zhang <zhangliguang@linux.alibaba.com>
> ---

Playing spot-the-difference with [v3], you've moved an empty line.

Please include a change log in this space below the '---' tearoff. This helps reviewers
know what you changed between versions, and git knows not to add stuff in here to the log.

This is still:
Reviewed-by: James Morse <james.morse@arm.com>


Thanks,

James

[v3]
https://lore.kernel.org/linux-acpi/1561258201-26917-1-git-send-email-zhangliguang@linux.alibaba.com/


>  drivers/acpi/apei/ghes.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
> 

[...]

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

* Re: [PATCH v4] ACPI / APEI: release resources if gen_pool_add fails
  2019-07-25 12:46 ` James Morse
@ 2019-07-26  9:29   ` 乱石
  2019-07-26 14:09     ` James Morse
  0 siblings, 1 reply; 6+ messages in thread
From: 乱石 @ 2019-07-26  9:29 UTC (permalink / raw)
  To: James Morse
  Cc: Rafael J. Wysocki, Len Brown, Tony Luck, Borislav Petkov, linux-acpi

Hi James,

在 2019/7/25 20:46, James Morse 写道:
> Hi Liguang,
>
> On 15/07/2019 07:58, luanshi wrote:
>> To avoid memory leaks, destroy ghes_estatus_pool and release memory
>> allocated via vmalloc() on errors in ghes_estatus_pool_init().
>>
>> Signed-off-by: Liguang Zhang <zhangliguang@linux.alibaba.com>
>> ---
> Playing spot-the-difference with [v3], you've moved an empty line.
>
> Please include a change log in this space below the '---' tearoff. This helps reviewers
> know what you changed between versions, and git knows not to add stuff in here to the log.
>
> This is still:
> Reviewed-by: James Morse <james.morse@arm.com>

Thanks for your review. Because your reviewed-by was given ealier, and 
the code is reconstructed,

so I remove the reviewed-by. I will send v5 by your suggestions.

Thanks,

Liguang

>
>
> Thanks,
>
> James
>
> [v3]
> https://lore.kernel.org/linux-acpi/1561258201-26917-1-git-send-email-zhangliguang@linux.alibaba.com/
>
>
>>   drivers/acpi/apei/ghes.c | 17 ++++++++++++++---
>>   1 file changed, 14 insertions(+), 3 deletions(-)
>>
> [...]

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

* Re: [PATCH v4] ACPI / APEI: release resources if gen_pool_add fails
  2019-07-26  9:29   ` 乱石
@ 2019-07-26 14:09     ` James Morse
  0 siblings, 0 replies; 6+ messages in thread
From: James Morse @ 2019-07-26 14:09 UTC (permalink / raw)
  To: 乱石
  Cc: Rafael J. Wysocki, Len Brown, Tony Luck, Borislav Petkov, linux-acpi

Hi Liguang,

On 26/07/2019 10:29, 乱石 wrote:
> 在 2019/7/25 20:46, James Morse 写道:
>> On 15/07/2019 07:58, luanshi wrote:
>>> To avoid memory leaks, destroy ghes_estatus_pool and release memory
>>> allocated via vmalloc() on errors in ghes_estatus_pool_init().
>>>
>>> Signed-off-by: Liguang Zhang <zhangliguang@linux.alibaba.com>
>>> ---
>> Playing spot-the-difference with [v3], you've moved an empty line.
>>
>> Please include a change log in this space below the '---' tearoff. This helps reviewers
>> know what you changed between versions, and git knows not to add stuff in here to the log.
>>
>> This is still:
>> Reviewed-by: James Morse <james.morse@arm.com>
> 
> Thanks for your review. Because your reviewed-by was given ealier, and the code is
> reconstructed,
> 
> so I remove the reviewed-by. I will send v5 by your suggestions.

There is no need to post a new version just to pick up the tags.

Having a versioned changelog on your future work makes it easier for reviewers to know
what changed between versions.


Thanks,

James

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

* [PATCH v4.1] ACPI / APEI: release resources if gen_pool_add fails
  2019-07-15  6:58 [PATCH v4] ACPI / APEI: release resources if gen_pool_add fails luanshi
  2019-07-25 12:46 ` James Morse
@ 2019-08-13 17:16 ` Borislav Petkov
  2019-08-26  9:06   ` Rafael J. Wysocki
  1 sibling, 1 reply; 6+ messages in thread
From: Borislav Petkov @ 2019-08-13 17:16 UTC (permalink / raw)
  To: luanshi, Rafael J. Wysocki
  Cc: Rafael J. Wysocki, Len Brown, James Morse, Tony Luck, linux-acpi

Hi,

here's v4.1 with the labels properly balanced.

Thx.

---
From: Liguang Zhang <zhangliguang@linux.alibaba.com>
Date: Mon, 15 Jul 2019 14:58:44 +0800
Subject: [PATCH] ACPI / APEI: Release resources if gen_pool_add() fails

Destroy ghes_estatus_pool and release memory allocated via vmalloc() on
errors in ghes_estatus_pool_init() in order to avoid memory leaks.

 [ bp: do the labels properly and with descriptive names and massage. ]

Signed-off-by: Liguang Zhang <zhangliguang@linux.alibaba.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: James Morse <james.morse@arm.com>
Cc: Len Brown <lenb@kernel.org>
Cc: linux-acpi@vger.kernel.org
Cc: Tony Luck <tony.luck@intel.com>
Link: https://lkml.kernel.org/r/1563173924-47479-1-git-send-email-zhangliguang@linux.alibaba.com
---
 drivers/acpi/apei/ghes.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
index a66e00fe31fe..66205ec54555 100644
--- a/drivers/acpi/apei/ghes.c
+++ b/drivers/acpi/apei/ghes.c
@@ -153,6 +153,7 @@ static void ghes_unmap(void __iomem *vaddr, enum fixed_addresses fixmap_idx)
 int ghes_estatus_pool_init(int num_ghes)
 {
 	unsigned long addr, len;
+	int rc;
 
 	ghes_estatus_pool = gen_pool_create(GHES_ESTATUS_POOL_MIN_ALLOC_ORDER, -1);
 	if (!ghes_estatus_pool)
@@ -164,7 +165,7 @@ int ghes_estatus_pool_init(int num_ghes)
 	ghes_estatus_pool_size_request = PAGE_ALIGN(len);
 	addr = (unsigned long)vmalloc(PAGE_ALIGN(len));
 	if (!addr)
-		return -ENOMEM;
+		goto err_pool_alloc;
 
 	/*
 	 * New allocation must be visible in all pgd before it can be found by
@@ -172,7 +173,19 @@ int ghes_estatus_pool_init(int num_ghes)
 	 */
 	vmalloc_sync_all();
 
-	return gen_pool_add(ghes_estatus_pool, addr, PAGE_ALIGN(len), -1);
+	rc = gen_pool_add(ghes_estatus_pool, addr, PAGE_ALIGN(len), -1);
+	if (rc)
+		goto err_pool_add;
+
+	return 0;
+
+err_pool_add:
+	vfree((void *)addr);
+
+err_pool_alloc:
+	gen_pool_destroy(ghes_estatus_pool);
+
+	return -ENOMEM;
 }
 
 static int map_gen_v2(struct ghes *ghes)
-- 
2.21.0


-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

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

* Re: [PATCH v4.1] ACPI / APEI: release resources if gen_pool_add fails
  2019-08-13 17:16 ` [PATCH v4.1] " Borislav Petkov
@ 2019-08-26  9:06   ` Rafael J. Wysocki
  0 siblings, 0 replies; 6+ messages in thread
From: Rafael J. Wysocki @ 2019-08-26  9:06 UTC (permalink / raw)
  To: Borislav Petkov; +Cc: luanshi, Len Brown, James Morse, Tony Luck, linux-acpi

On Tuesday, August 13, 2019 7:16:19 PM CEST Borislav Petkov wrote:
> Hi,
> 
> here's v4.1 with the labels properly balanced.

Applied, thanks!

> ---
> From: Liguang Zhang <zhangliguang@linux.alibaba.com>
> Date: Mon, 15 Jul 2019 14:58:44 +0800
> Subject: [PATCH] ACPI / APEI: Release resources if gen_pool_add() fails
> 
> Destroy ghes_estatus_pool and release memory allocated via vmalloc() on
> errors in ghes_estatus_pool_init() in order to avoid memory leaks.
> 
>  [ bp: do the labels properly and with descriptive names and massage. ]
> 
> Signed-off-by: Liguang Zhang <zhangliguang@linux.alibaba.com>
> Signed-off-by: Borislav Petkov <bp@suse.de>
> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
> Cc: James Morse <james.morse@arm.com>
> Cc: Len Brown <lenb@kernel.org>
> Cc: linux-acpi@vger.kernel.org
> Cc: Tony Luck <tony.luck@intel.com>
> Link: https://lkml.kernel.org/r/1563173924-47479-1-git-send-email-zhangliguang@linux.alibaba.com
> ---
>  drivers/acpi/apei/ghes.c | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
> index a66e00fe31fe..66205ec54555 100644
> --- a/drivers/acpi/apei/ghes.c
> +++ b/drivers/acpi/apei/ghes.c
> @@ -153,6 +153,7 @@ static void ghes_unmap(void __iomem *vaddr, enum fixed_addresses fixmap_idx)
>  int ghes_estatus_pool_init(int num_ghes)
>  {
>  	unsigned long addr, len;
> +	int rc;
>  
>  	ghes_estatus_pool = gen_pool_create(GHES_ESTATUS_POOL_MIN_ALLOC_ORDER, -1);
>  	if (!ghes_estatus_pool)
> @@ -164,7 +165,7 @@ int ghes_estatus_pool_init(int num_ghes)
>  	ghes_estatus_pool_size_request = PAGE_ALIGN(len);
>  	addr = (unsigned long)vmalloc(PAGE_ALIGN(len));
>  	if (!addr)
> -		return -ENOMEM;
> +		goto err_pool_alloc;
>  
>  	/*
>  	 * New allocation must be visible in all pgd before it can be found by
> @@ -172,7 +173,19 @@ int ghes_estatus_pool_init(int num_ghes)
>  	 */
>  	vmalloc_sync_all();
>  
> -	return gen_pool_add(ghes_estatus_pool, addr, PAGE_ALIGN(len), -1);
> +	rc = gen_pool_add(ghes_estatus_pool, addr, PAGE_ALIGN(len), -1);
> +	if (rc)
> +		goto err_pool_add;
> +
> +	return 0;
> +
> +err_pool_add:
> +	vfree((void *)addr);
> +
> +err_pool_alloc:
> +	gen_pool_destroy(ghes_estatus_pool);
> +
> +	return -ENOMEM;
>  }
>  
>  static int map_gen_v2(struct ghes *ghes)
> 





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

end of thread, other threads:[~2019-08-26  9:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-15  6:58 [PATCH v4] ACPI / APEI: release resources if gen_pool_add fails luanshi
2019-07-25 12:46 ` James Morse
2019-07-26  9:29   ` 乱石
2019-07-26 14:09     ` James Morse
2019-08-13 17:16 ` [PATCH v4.1] " Borislav Petkov
2019-08-26  9:06   ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).