From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1425090AbdEYSxK (ORCPT ); Thu, 25 May 2017 14:53:10 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:33793 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424944AbdEYSvg (ORCPT ); Thu, 25 May 2017 14:51:36 -0400 From: Manfred Spraul To: mtk.manpages@gmail.com, Andrew Morton , Kees Cook Cc: LKML , 1vier1@web.de, Davidlohr Bueso , mingo@kernel.org, peterz@infradead.org, fabf@skynet.be, Manfred Spraul Subject: [PATCH 17/20] ipc/shm: Remove special shm_alloc/free Date: Thu, 25 May 2017 20:51:04 +0200 Message-Id: <20170525185107.12869-18-manfred@colorfullife.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170525185107.12869-1-manfred@colorfullife.com> References: <20170508222345.GA52073@beast> <20170525185107.12869-1-manfred@colorfullife.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kees Cook There is nothing special about the shm_alloc/free routines any more, so remove them to make code more readable. Signed-off-by: Kees Cook [manfred@colorfullife.com: Rediff, to continue to keep rcu for free calls after a successful security_shm_alloc()] Signed-off-by: Manfred Spraul --- ipc/shm.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/ipc/shm.c b/ipc/shm.c index b85db5a..ec5688e 100644 --- a/ipc/shm.c +++ b/ipc/shm.c @@ -172,11 +172,6 @@ static inline void shm_lock_by_ptr(struct shmid_kernel *ipcp) ipc_lock_object(&ipcp->shm_perm); } -static void __shm_free(struct shmid_kernel *shp) -{ - kvfree(shp); -} - static void shm_rcu_free(struct rcu_head *head) { struct kern_ipc_perm *ptr = container_of(head, struct kern_ipc_perm, @@ -184,7 +179,7 @@ static void shm_rcu_free(struct rcu_head *head) struct shmid_kernel *shp = container_of(ptr, struct shmid_kernel, shm_perm); security_shm_free(shp); - __shm_free(shp); + kvfree(shp); } static inline void shm_rmid(struct ipc_namespace *ns, struct shmid_kernel *s) @@ -518,17 +513,6 @@ static const struct vm_operations_struct shm_vm_ops = { #endif }; -static struct shmid_kernel *shm_alloc(void) -{ - struct shmid_kernel *shp; - - shp = kvmalloc(sizeof(*shp), GFP_KERNEL); - if (unlikely(!shp)) - return NULL; - - return shp; -} - /** * newseg - Create a new shared memory segment * @ns: namespace @@ -558,8 +542,8 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params) ns->shm_tot + numpages > ns->shm_ctlall) return -ENOSPC; - shp = shm_alloc(); - if (!shp) + shp = kvmalloc(sizeof(*shp), GFP_KERNEL); + if (unlikely(!shp)) return -ENOMEM; shp->shm_perm.key = key; @@ -569,7 +553,7 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params) shp->shm_perm.security = NULL; error = security_shm_alloc(shp); if (error) { - __shm_free(shp); + kvfree(shp); return error; } -- 2.9.3