From: Theodore Ts'o Date: Sat, 9 Nov 2019 02:25:59 +0000 (-0500) Subject: e2fsck/revoke.c: sync kernel's adoption of kmalloc_array() X-Git-Tag: v1.46.0~94 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a8833696e84db27c34a231d83fdc86871217208d;p=thirdparty%2Fe2fsprogs.git e2fsck/revoke.c: sync kernel's adoption of kmalloc_array() Sync the changes to e2fsck/revoke.c from commit 6da2ec56059c ("treewide: kmalloc() -> kmalloc_array()"), and add the emulation of kmalloc_array() to e2fsck/jfs_user.h Signed-off-by: Theodore Ts'o --- diff --git a/e2fsck/jfs_user.h b/e2fsck/jfs_user.h index 239ac1dde..1445c3e6a 100644 --- a/e2fsck/jfs_user.h +++ b/e2fsck/jfs_user.h @@ -92,6 +92,13 @@ typedef struct { #define kmalloc(len, flags) malloc(len) #define kfree(p) free(p) +static inline void *kmalloc_array(unsigned n, unsigned size, int flags) +{ + if (n && (~0U)/n < size) + return NULL; + return malloc(n * size); +} + #define cond_resched() do { } while (0) #define __init diff --git a/e2fsck/revoke.c b/e2fsck/revoke.c index 3fadf5718..3f7833096 100644 --- a/e2fsck/revoke.c +++ b/e2fsck/revoke.c @@ -228,7 +228,7 @@ static struct jbd2_revoke_table_s *jbd2_journal_init_revoke_table(int hash_size) table->hash_size = hash_size; table->hash_shift = shift; table->hash_table = - kmalloc(hash_size * sizeof(struct list_head), GFP_KERNEL); + kmalloc_array(hash_size, sizeof(struct list_head), GFP_KERNEL); if (!table->hash_table) { kmem_cache_free(jbd2_revoke_table_cache, table); table = NULL;