Re: [PATCH] ACPI / APEI: release resources if gen_pool_add fails

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




在 2019/6/14 22:51, James Morse 写道:
Hi Liguang,

On 14/06/2019 10:49, 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.zlg <zhangliguang@xxxxxxxxxxxxxxxxx>
(I'm surprised your name has a '.' in it!)

Nit: This is v2. Please add a version number in the subject, e.g.:
| [PATCH v2] ACPI / APEI: release resources if gen_pool_add fails

This makes it easy for reviewers to know which is the latest. git format-patch will do
this for you if you add '-v 2' to its command-line.


diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
index 993940d..8472c96 100644
--- a/drivers/acpi/apei/ghes.c
+++ b/drivers/acpi/apei/ghes.c
@@ -163,8 +164,10 @@ 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)
+	if (!addr) {
+		gen_pool_destroy(ghes_estatus_pool);
  		return -ENOMEM;
+	}
/*
  	 * New allocation must be visible in all pgd before it can be found by
@@ -172,7 +175,12 @@ 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) {
+		vfree(addr);
addr here is unsigned long, but vfree() wants a void *.

vfree() first leaves us with a pool containing memory we've vfree()d, which doesn't feel
like a good state to step through.
Can we vfree() after gen_pool_destroy()?

Hi James,

 I will modify this patch by your suggestion and send the patch v3 for review.

Thanks,

Liguang




+		gen_pool_destroy(ghes_estatus_pool);
+	}
+	return rc;
  }

With that:
Reviewed-by: James Morse <james.morse@xxxxxxx>
Tested-by: James Morse <james.morse@xxxxxxx>


Thanks for cleaning this up!

James



[Index of Archives]     [Linux IBM ACPI]     [Linux Power Management]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux