From: Mateusz Majewski Date: Wed, 31 Aug 2022 11:18:51 +0000 (+0200) Subject: zlogger: switch from kzalloc to __get_free_pages X-Git-Tag: submit/tizen/20220906.135332~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2e414aa86a2e3370e2aa85b8a237a924ec5f0b96;p=platform%2Fkernel%2Flinux-tizen-modules-source.git zlogger: switch from kzalloc to __get_free_pages Since we want to mmap the memory in userspace, it's important for the memory to be consisting of full pages. Even though this has been true in our tests, kzalloc does not guarantee this and there is a danger of this changing in the future kernel releases. Instead, we can use __get_free_pages, which explicitly returns a number of contiguous pages. Change-Id: I4db57e37fbbcd17716718ed81ef2a6b79e4b1afc --- diff --git a/kernel/zlogger/zlogger.c b/kernel/zlogger/zlogger.c index 796836d..ea6c99b 100644 --- a/kernel/zlogger/zlogger.c +++ b/kernel/zlogger/zlogger.c @@ -46,6 +46,7 @@ #define ZLOGGER_SMACK_LABEL "*" #define BLOCK_RATIO(count) (count*100/ZLOGGER_BLOCK_COUNT) +#define MAP_ORDER (get_order(ZLOGGER_MAP_SIZE)) #define ZLOG_FD_BUFER (2 * ZLOGGER_MB) @@ -786,7 +787,7 @@ static int zlogger_init(void) hash_init(g_thread_table->data); for (g_shm_ptr_i = 0; g_shm_ptr_i < ZLOGGER_DEVICE_COUNT; g_shm_ptr_i++) { - g_shm_ptr[g_shm_ptr_i] = kzalloc(ZLOGGER_MAP_SIZE, GFP_KERNEL); + g_shm_ptr[g_shm_ptr_i] = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, MAP_ORDER); if (g_shm_ptr[g_shm_ptr_i] == NULL) { r = -ENOMEM; goto out_free_g_thread_table_g_shm_ptr; @@ -841,7 +842,7 @@ out_free_zlog_task: out_free_g_thread_table_g_shm_ptr: for (i = 0; i < g_shm_ptr_i; ++i) { - kfree(g_shm_ptr[i]); + free_pages((unsigned long)g_shm_ptr[i], MAP_ORDER); g_shm_ptr[i] = NULL; } @@ -872,7 +873,7 @@ static void zlogger_exit(void) g_thread_table = NULL; for (i = 0; i < ZLOGGER_DEVICE_COUNT; i++) { - kfree(g_shm_ptr[i]); + free_pages((unsigned long)g_shm_ptr[i], MAP_ORDER); g_shm_ptr[i] = NULL; }