[PATCH v2] uprobes: Use better bitmap_zalloc/free

From: Kefeng Wang
Date: Sun May 30 2021 - 21:29:04 EST


Use better bitmap_zalloc/free() to allocate and free bitmap.

Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Cc: Mark Rutland <mark.rutland@xxxxxxx>
Signed-off-by: Kefeng Wang <wangkefeng.wang@xxxxxxxxxx>
---
v2: fix the copy err, should found it when enable UPROBES
kernel/events/uprobes.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 907d4ee00cb2..3f1b8e9d9af6 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1487,8 +1487,7 @@ static struct xol_area *__create_xol_area(unsigned long vaddr)
if (unlikely(!area))
goto out;

- area->bitmap = kcalloc(BITS_TO_LONGS(UINSNS_PER_PAGE), sizeof(long),
- GFP_KERNEL);
+ area->bitmap = bitmap_zalloc(UINSNS_PER_PAGE, GFP_KERNEL);
if (!area->bitmap)
goto free_area;

@@ -1512,7 +1511,7 @@ static struct xol_area *__create_xol_area(unsigned long vaddr)

__free_page(area->pages[0]);
free_bitmap:
- kfree(area->bitmap);
+ bitmap_free(area->bitmap);
free_area:
kfree(area);
out:
@@ -1553,7 +1552,7 @@ void uprobe_clear_state(struct mm_struct *mm)
return;

put_page(area->pages[0]);
- kfree(area->bitmap);
+ bitmap_free(area->bitmap);
kfree(area);
}

--
2.26.2