From a8833696e84db27c34a231d83fdc86871217208d Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 8 Nov 2019 21:25:59 -0500 Subject: [PATCH] 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 --- e2fsck/jfs_user.h | 7 +++++++ e2fsck/revoke.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/e2fsck/jfs_user.h b/e2fsck/jfs_user.h index 239ac1d..1445c3e 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 3fadf57..3f78330 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; -- 1.8.3.1