+ ipc-semc-replace-kvmalloc-memset-with-kvzalloc-and-use-struct_size.patch added to -mm tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The patch titled
     Subject: ipc/sem.c: replace kvmalloc/memset with kvzalloc and use struct_size
has been added to the -mm tree.  Its filename is
     ipc-semc-replace-kvmalloc-memset-with-kvzalloc-and-use-struct_size.patch

This patch should soon appear at
    http://ozlabs.org/~akpm/mmots/broken-out/ipc-semc-replace-kvmalloc-memset-with-kvzalloc-and-use-struct_size.patch
and later at
    http://ozlabs.org/~akpm/mmotm/broken-out/ipc-semc-replace-kvmalloc-memset-with-kvzalloc-and-use-struct_size.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next and is updated
there every 3-4 working days

------------------------------------------------------
From: "Gustavo A. R. Silva" <gustavo@xxxxxxxxxxxxxx>
Subject: 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 <gustavo@xxxxxxxxxxxxxx>
Cc: Davidlohr Bueso <dave@xxxxxxxxxxxx>
Cc: Manfred Spraul <manfred@xxxxxxxxxxxxxxxx>
Cc: Kees Cook <keescook@xxxxxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---


--- a/ipc/sem.c~ipc-semc-replace-kvmalloc-memset-with-kvzalloc-and-use-struct_size
+++ a/ipc/sem.c
@@ -488,18 +488,14 @@ static inline void sem_rmid(struct ipc_n
 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;
 }
 
_

Patches currently in -mm which might be from gustavo@xxxxxxxxxxxxxx are

ocfs2-use-zero-sized-array-and-struct_size-in-kzalloc.patch
mm-memcontrol-use-struct_size-in-kmalloc.patch
gcov-use-struct_size-in-kzalloc.patch
ipc-semc-replace-kvmalloc-memset-with-kvzalloc-and-use-struct_size.patch




[Index of Archives]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux