Skip to content

Commit b9ca93b

Browse files
MrVanmstsirkin
authored andcommitted
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>
1 parent 697d154 commit b9ca93b

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

tools/virtio/linux/kernel.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <linux/compiler.h>
1313
#include <linux/types.h>
14+
#include <linux/overflow.h>
1415
#include <linux/list.h>
1516
#include <linux/printk.h>
1617
#include <linux/bug.h>
@@ -117,6 +118,16 @@ static inline void free_page(unsigned long addr)
117118
# define unlikely(x) (__builtin_expect(!!(x), 0))
118119
# endif
119120

121+
static inline void *krealloc_array(void *p, size_t new_n, size_t new_size, gfp_t gfp)
122+
{
123+
size_t bytes;
124+
125+
if (unlikely(check_mul_overflow(new_n, new_size, &bytes)))
126+
return NULL;
127+
128+
return krealloc(p, bytes, gfp);
129+
}
130+
120131
#define pr_err(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
121132
#ifdef DEBUG
122133
#define pr_debug(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
@@ -126,8 +137,6 @@ static inline void free_page(unsigned long addr)
126137
#define dev_err(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__)
127138
#define dev_warn(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__)
128139

129-
#define WARN_ON_ONCE(cond) (unlikely(cond) ? fprintf (stderr, "WARNING\n") : 0)
130-
131140
#define min(x, y) ({ \
132141
typeof(x) _min1 = (x); \
133142
typeof(y) _min2 = (y); \

0 commit comments

Comments
 (0)