Staging: android: ion: fix to set cached element of pool always 75/251375/1
authorSeung-Woo Kim <sw0312.kim@samsung.com>
Wed, 13 Jan 2021 07:52:58 +0000 (16:52 +0900)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Wed, 13 Jan 2021 08:01:55 +0000 (17:01 +0900)
The allocated memory with kmalloc() can have invalid value. To
avoid using the invalid value, always set cached element.

This removes below UBSAN warning:
   UBSAN: Undefined behaviour in drivers/staging/android/ion/ion_page_pool.c:33:11
   load of value 152 is not a valid value for type '_Bool'
   ...
   [<ffffff9009b89e48>] __ubsan_handle_load_invalid_value+0x80/0x90
   [<ffffff900a2c4044>] ion_page_pool_alloc+0x154/0x180
   [<ffffff900a2c5b60>] ion_system_heap_allocate+0x2b8/0xa68
   [<ffffff900a2c0688>] ion_alloc+0x238/0x9c8
   ...

Change-Id: I86e0ee70404bb074dad3b73dccec31ebcf2c7c72
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
drivers/staging/android/ion/ion_page_pool.c

index aea89c1..c34d921 100644 (file)
@@ -163,8 +163,7 @@ struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order,
        pool->order = order;
        mutex_init(&pool->mutex);
        plist_node_init(&pool->list, order);
-       if (cached)
-               pool->cached = true;
+       pool->cached = cached;
 
        return pool;
 }