Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F163908088
D56453.id176150.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D56453.id176150.diff
View Options
diff --git a/sys/compat/linuxkpi/common/include/linux/slab.h b/sys/compat/linuxkpi/common/include/linux/slab.h
--- a/sys/compat/linuxkpi/common/include/linux/slab.h
+++ b/sys/compat/linuxkpi/common/include/linux/slab.h
@@ -141,6 +141,13 @@
/*
* Base functions with a native implementation.
*/
+
+static inline size_t
+ksize(const void *ptr)
+{
+ return (malloc_usable_size(ptr));
+}
+
static inline void *
kmalloc(size_t size, gfp_t flags)
{
@@ -264,22 +271,28 @@
return (kvmalloc(size * n, flags));
}
+void * lkpi_kvrealloc(const void *ptr, size_t oldsize, size_t newsize, gfp_t flags);
+
+#if defined(LINUXKPI_VERSION) && LINUXKPI_VERSION < 61200
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));
+ return (lkpi_kvrealloc(ptr, oldsize, newsize, flags));
+}
+#else
+static inline void *
+kvrealloc(const void *ptr, size_t newsize, gfp_t flags)
+{
+ size_t oldsize;
- newptr = kvmalloc(newsize, flags);
- if (newptr != NULL) {
- memcpy(newptr, ptr, oldsize);
- kvfree(ptr);
- }
+ if (!ZERO_OR_NULL_PTR(ptr))
+ oldsize = ksize(ptr);
+ else
+ oldsize = 0;
- return (newptr);
+ return (lkpi_kvrealloc(ptr, oldsize, newsize, flags));
}
+#endif
/*
* Misc.
@@ -294,12 +307,6 @@
zfree(__DECONST(void *, ptr), M_KMALLOC);
}
-static inline size_t
-ksize(const void *ptr)
-{
- return (malloc_usable_size(ptr));
-}
-
static inline size_t
kmalloc_size_roundup(size_t size)
{
diff --git a/sys/compat/linuxkpi/common/src/linux_slab.c b/sys/compat/linuxkpi/common/src/linux_slab.c
--- a/sys/compat/linuxkpi/common/src/linux_slab.c
+++ b/sys/compat/linuxkpi/common/src/linux_slab.c
@@ -278,6 +278,44 @@
return (nptr);
}
+void *
+lkpi_kvrealloc(const void *ptr, size_t oldsize, size_t newsize, gfp_t flags)
+{
+ void *newptr;
+
+ /*
+ * We replicate the behaviour of krealloc() instead of calling it
+ * because we don't need to allocate physically contiguous memory.
+ */
+
+ if (newsize == 0) {
+ kfree(ptr);
+ return (ZERO_SIZE_PTR);
+ }
+
+ if (ptr == NULL) {
+ newptr = kvmalloc(newsize, flags);
+ return (newptr);
+ }
+
+ newptr = realloc(
+ __DECONST(void *, ptr), newsize, M_KMALLOC,
+ linux_check_m_flags(flags));
+
+ if (newptr == NULL) {
+ newptr = kvmalloc(newsize, flags);
+ if (newptr == NULL)
+ return (NULL);
+
+ if (ptr != NULL) {
+ memcpy(newptr, ptr, oldsize);
+ kfree(ptr);
+ }
+ }
+
+ return (newptr);
+}
+
struct lkpi_kmalloc_ctx {
size_t size;
gfp_t flags;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Jul 28, 2:47 AM (1 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
35628091
Default Alt Text
D56453.id176150.diff (2 KB)
Attached To
Mode
D56453: linuxkpi: Add Linux 6.12 variant of `kvrealloc()`
Attached
Detach File
Event Timeline
Log In to Comment