From: Gustavo A. R. Silva Date: Fri, 8 Mar 2019 00:30:26 +0000 (-0800) Subject: ipc/sem.c: replace kvmalloc/memset with kvzalloc and use struct_size X-Git-Tag: v5.4-rc1~1483^2~18 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4a2ae92993be24ba727faa733e99d7980d389ec0;p=platform%2Fkernel%2Flinux-rpi.git ipc/sem.c: replace kvmalloc/memset with kvzalloc and use struct_size Use kvzalloc() instead of kvmalloc() and memset(). Also, make use of the struct_size() helper instead of the open-coded version in order to avoid any potential type mistakes. This code was detected with the help of Coccinelle. Link: http://lkml.kernel.org/r/20190131214221.GA28930@embeddedor Signed-off-by: Gustavo A. R. Silva Reviewed-by: Andrew Morton Cc: Davidlohr Bueso Cc: Manfred Spraul Cc: Kees Cook Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/ipc/sem.c b/ipc/sem.c index a188d1b0..7da4504 100644 --- a/ipc/sem.c +++ b/ipc/sem.c @@ -488,18 +488,14 @@ static inline void sem_rmid(struct ipc_namespace *ns, struct sem_array *s) static struct sem_array *sem_alloc(size_t nsems) { struct sem_array *sma; - size_t size; if (nsems > (INT_MAX - sizeof(*sma)) / sizeof(sma->sems[0])) return NULL; - size = sizeof(*sma) + nsems * sizeof(sma->sems[0]); - sma = kvmalloc(size, GFP_KERNEL); + sma = kvzalloc(struct_size(sma, sems, nsems), GFP_KERNEL); if (unlikely(!sma)) return NULL; - memset(sma, 0, size); - return sma; }