Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools/virtio: add krealloc_array

krealloc_array is used in drivers/vhost/vringh.c, add it to avoid build
failure.

Drop WARN_ON_ONCE, because duplicated with the one in bug.h

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Link: https://lore.kernel.org/r/20201209084205.24062-3-peng.fan@oss.nxp.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

authored by

Peng Fan and committed by
Michael S. Tsirkin
b9ca93bc 697d1549

+11 -2
+11 -2
tools/virtio/linux/kernel.h
··· 11 11 12 12 #include <linux/compiler.h> 13 13 #include <linux/types.h> 14 + #include <linux/overflow.h> 14 15 #include <linux/list.h> 15 16 #include <linux/printk.h> 16 17 #include <linux/bug.h> ··· 118 117 # define unlikely(x) (__builtin_expect(!!(x), 0)) 119 118 # endif 120 119 120 + static inline void *krealloc_array(void *p, size_t new_n, size_t new_size, gfp_t gfp) 121 + { 122 + size_t bytes; 123 + 124 + if (unlikely(check_mul_overflow(new_n, new_size, &bytes))) 125 + return NULL; 126 + 127 + return krealloc(p, bytes, gfp); 128 + } 129 + 121 130 #define pr_err(format, ...) fprintf (stderr, format, ## __VA_ARGS__) 122 131 #ifdef DEBUG 123 132 #define pr_debug(format, ...) fprintf (stderr, format, ## __VA_ARGS__) ··· 136 125 #endif 137 126 #define dev_err(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__) 138 127 #define dev_warn(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__) 139 - 140 - #define WARN_ON_ONCE(cond) (unlikely(cond) ? fprintf (stderr, "WARNING\n") : 0) 141 128 142 129 #define min(x, y) ({ \ 143 130 typeof(x) _min1 = (x); \