Re: [PATCH] lkdtm: use kmalloc() instead of __get_free_page

From: Mike Rapoport

Date: Sun Jul 26 2026 - 03:03:42 EST


On Wed, Jul 22, 2026 at 11:02:46PM +0000, Mahad Ibrahim wrote:
> lkdtm_debugfs_entry and direct_entry use __get_free_page to allocate a
> temporary buffer, perform copy_from_user to get the crashtype name,
> strim() to strip whitespace and find_crashtype to find the corresponding
> crashtype that is being requested.
>
> The lkdtm_debugfs_read uses __get_free_page to allocate a temporary
> buffer to store all the available crashtypes, and then copy it to
> userspace.
>
> The buffers that are allocated can be allocated with kmalloc as there is
> nothing special that requires a struct page, or the page allocator.
>
> kmalloc() additionally provides a better API that doesn't require ugly
> casts which obfuscate the code and kfree does not need to know the size
> of the freed object.
>
> Replace use of __get_free_page() with kmalloc().
>
> Signed-off-by: Mahad Ibrahim <mahad.ibrahim.dev@xxxxxxxxx>

Acked-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>

> ---
> drivers/misc/lkdtm/core.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)

--
Sincerely yours,
Mike.