aboutsummaryrefslogtreecommitdiff
path: root/sys/compat/linuxkpi/common/src/linux_slab.c
diff options
context:
space:
mode:
authorBjoern A. Zeeb <bz@FreeBSD.org>2025-03-29 17:33:08 +0000
committerBjoern A. Zeeb <bz@FreeBSD.org>2025-04-18 14:35:58 +0000
commitebe210ca703bd584274396b2c0fa1694750f05c1 (patch)
tree0906921a5738d96204224a7f205c4c483757c84d /sys/compat/linuxkpi/common/src/linux_slab.c
parent516eb937b274c34793f9b640e547eee0dc185b2d (diff)
LinuxKPI; cleanup slab.h a bit; move more free() into slab.c
Move kfree() into slab.c as an implementation and hide the private function linux_kfree_async() entirely. Remove a ; at the end of a define and sort some defines into place. Remove extern from function declarations and move the closer to where they belong. Sort the functions into "base allocator/free" functions--these have an implementation in slab.c and are ensuring contiguous physical memory allocations. Followed by inline functions using these base allocators to implement their functionality; vmalloc/kvalloc, and misc functions. Sponsored by: The FreeBSD Foundation Reviewed by: dumbbell Differential Revision: https://reviews.freebsd.org/D49572 (cherry picked from commit a3e6f97bf57c1d323487d07369aec66542f995ce)
Diffstat (limited to 'sys/compat/linuxkpi/common/src/linux_slab.c')
-rw-r--r--sys/compat/linuxkpi/common/src/linux_slab.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/sys/compat/linuxkpi/common/src/linux_slab.c b/sys/compat/linuxkpi/common/src/linux_slab.c
index abcffdb094f5..3d75ca480661 100644
--- a/sys/compat/linuxkpi/common/src/linux_slab.c
+++ b/sys/compat/linuxkpi/common/src/linux_slab.c
@@ -1,6 +1,10 @@
/*-
* Copyright (c) 2017 Mellanox Technologies, Ltd.
* All rights reserved.
+ * Copyright (c) 2024-2025 The FreeBSD Foundation
+ *
+ * Portions of this software were developed by Björn Zeeb
+ * under sponsorship from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -303,7 +307,7 @@ linux_kfree_async_fn(void *context, int pending)
static struct task linux_kfree_async_task =
TASK_INITIALIZER(0, linux_kfree_async_fn, &linux_kfree_async_task);
-void
+static void
linux_kfree_async(void *addr)
{
if (addr == NULL)
@@ -311,3 +315,16 @@ linux_kfree_async(void *addr)
llist_add(addr, &linux_kfree_async_list);
taskqueue_enqueue(linux_irq_work_tq, &linux_kfree_async_task);
}
+
+void
+lkpi_kfree(const void *ptr)
+{
+ if (ZERO_OR_NULL_PTR(ptr))
+ return;
+
+ if (curthread->td_critnest != 0)
+ linux_kfree_async(__DECONST(void *, ptr));
+ else
+ free(__DECONST(void *, ptr), M_KMALLOC);
+}
+