Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 21 Jul 2024 13:14:46 GMT
From:      Vladimir Kondratyev <wulf@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: ab6e1167909b - main - LinuxKPI: Add kvrealloc to linux/slab.h
Message-ID:  <202407211314.46LDEk5T022943@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202407211314.46LDEk5T022943>