Skip to contentSkip to conversation

mm-slab-provide-krealloc_array.patch removed from -mm tree

merged [email protected] 1 participant 1 message Dec 15, 2020

lore
Share & tools
lore

[email protected]

author tree notice Applied
#0 lore raw

The patch titled
Subject: mm: slab: provide krealloc_array()
has been removed from the -mm tree. Its filename was
mm-slab-provide-krealloc_array.patch

This patch was dropped because it was merged into mainline or a subsystem tree

------------------------------------------------------
From: Bartosz Golaszewski <[email protected]>
Subject: mm: slab: provide krealloc_array()

When allocating an array of elements, users should check for multiplication overflow or preferably use one of the provided helpers
like: kmalloc_array().

There's no krealloc_array() counterpart but there are many users who use regular krealloc() to reallocate arrays. Let's provide an actual krealloc_array() implementation.

While at it: add some documentation regarding krealloc.

Cc Alexander Shishkin <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Christian Knig <[email protected]>
Cc Christoph Lameter <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc David Airlie <[email protected]>
Cc David Rientjes <[email protected]>
Cc Gustavo Padovan <[email protected]>
Cc James Morse <[email protected]>
Cc Jaroslav Kysela <[email protected]>
Cc Jason Wang <[email protected]>
Cc Joonsoo Kim <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Mauro Carvalho Chehab <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc "Michael S . Tsirkin" <[email protected]>
Cc Pekka Enberg <[email protected]>
Cc Robert Richter <[email protected]>
Cc Sumit Semwal <[email protected]>
Cc Takashi Iwai <[email protected]>
Cc Takashi Iwai <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Cc Tony Luck <[email protected]>

---

 Documentation/core-api/memory-allocation.rst |    4 +++
 include/linux/slab.h                         |   18 +++++++++++++++++
 2 files changed, 22 insertions(+)
Documentation/core-api/memory-allocation.rst renamed from Documentation/core-api/memory-allocation.rst~mm-slab-provide-krealloc_array +4 -0
@@ -147,6 +147,10 @@ The address of a chunk allocated with `k
 ARCH_KMALLOC_MINALIGN bytes.  For sizes which are a power of two, the
 alignment is also guaranteed to be at least the respective size.
 
+Chunks allocated with kmalloc() can be resized with krealloc(). Similarly
+to kmalloc_array(): a helper for resizing arrays is provided in the form of
+krealloc_array().
+
 For large allocations you can use vmalloc() and vzalloc(), or directly
 request pages from the page allocator. The memory allocated by `vmalloc`
 and related functions is not physically contiguous.
include/linux/slab.h renamed from include/linux/slab.h~mm-slab-provide-krealloc_array +18 -0
@@ -593,6 +593,24 @@ static inline void *kmalloc_array(size_t
 }
 
 /**
+ * krealloc_array - reallocate memory for an array.
+ * @p: pointer to the memory chunk to reallocate
+ * @new_n: new number of elements to alloc
+ * @new_size: new size of a single member of the array
+ * @flags: the type of memory to allocate (see kmalloc)
+ */
+static __must_check inline void *
+krealloc_array(void *p, size_t new_n, size_t new_size, gfp_t flags)
+{
+	size_t bytes;
+
+	if (unlikely(check_mul_overflow(new_n, new_size, &bytes)))
+		return NULL;
+
+	return krealloc(p, bytes, flags);
+}
+
+/**
  * kcalloc - allocate memory for an array. The memory is set to zero.
  * @n: number of elements.
  * @size: element size.

_

Patches currently in -mm which might be from [email protected] are