Open kees opened 2 years ago
Idea from keithp: create a wrapper func to re-assign __alloc_size()
as if we went through realloc()
. For example:
static inline __alloc_size(2) void *__resize_kmalloc(void *objp, size)
{
return objp;
}
#define ksize(objp) ({ \
/* \
* Getting the actual allocation size means the __alloc_size \
* hints are no longer valid, and the compiler needs to \
* learn the new one. \
*/ \
size_t __new_kmalloc_size; \
__new_kmalloc_size = _ksize(objp); \
objp = __resize_kmalloc(objp, __new_kmalloc_size); \
__new_kmalloc_size; \
})
The wrapper won't work because GCC ignores __alloc_size
on inlines. 😠
So, introduce kmalloc_size_roundup()
and remove the side-effect from ksize()
.
There needs to be a way to deal with
__alloc_size
not matchingksize()
.https://lore.kernel.org/lkml/202202281516.19274C0@keescook/
Plan: remove side-effect from ksize() and refactor all users to either use krealloc() afterwards, or kmalloc_roundup_size() before.
in v6.1:
in -next:
partially reviewed:
unreviewed:
finally: