git: ab6e1167909b - main - LinuxKPI: Add kvrealloc to linux/slab.h
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 21 Jul 2024 13:14:46 UTC
The branch main has been updated by wulf:
URL: https://cgit.FreeBSD.org/src/commit/?id=ab6e1167909bf1e2792a2ba33000e13d33aaf551
commit ab6e1167909bf1e2792a2ba33000e13d33aaf551
Author: Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2024-07-21 13:08:28 +0000
Commit: Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2024-07-21 13:08:28 +0000
LinuxKPI: Add kvrealloc to linux/slab.h
Sponsored by: Serenity Cyber Security, LLC
MFC after: 1 week
Reviewed by: manu
Differential Revision: https://reviews.freebsd.org/D45616
---
sys/compat/linuxkpi/common/include/linux/slab.h | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/sys/compat/linuxkpi/common/include/linux/slab.h b/sys/compat/linuxkpi/common/include/linux/slab.h
index 298306b6ea05..e2d17e0558c2 100644
--- a/sys/compat/linuxkpi/common/include/linux/slab.h
+++ b/sys/compat/linuxkpi/common/include/linux/slab.h
@@ -91,6 +91,8 @@ struct linux_kmem_cache;
#define ZERO_SIZE_PTR ((void *)16)
#define ZERO_OR_NULL_PTR(x) ((x) == NULL || (x) == ZERO_SIZE_PTR)
+extern void *lkpi_kmalloc(size_t size, gfp_t flags);
+
static inline gfp_t
linux_check_m_flags(gfp_t flags)
{
@@ -212,13 +214,29 @@ kfree_sensitive(const void *ptr)
zfree(__DECONST(void *, ptr), M_KMALLOC);
}
+static inline void *
+kvrealloc(const void *ptr, size_t oldsize, size_t newsize, gfp_t flags)
+{
+ void *newptr;
+
+ if (newsize <= oldsize)
+ return (__DECONST(void *, ptr));
+
+ newptr = kvmalloc(newsize, flags);
+ if (newptr != NULL) {
+ memcpy(newptr, ptr, oldsize);
+ kvfree(ptr);
+ }
+
+ return (newptr);
+}
+
static inline size_t
ksize(const void *ptr)
{
return (malloc_usable_size(ptr));
}
-extern void *lkpi_kmalloc(size_t size, gfp_t flags);
extern struct linux_kmem_cache *linux_kmem_cache_create(const char *name,
size_t size, size_t align, unsigned flags, linux_kmem_ctor_t *ctor);
extern void *lkpi_kmem_cache_alloc(struct linux_kmem_cache *, gfp_t);