summaryrefslogtreecommitdiffstats
path: root/ipc/shm.c
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2017-07-12 17:35:25 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-07-12 19:26:02 -0400
commit42e618f77dabc82c697915c193d729e9d16e2a75 (patch)
treeb473212b03b2c689aef6aa27beee310fdd15824c /ipc/shm.c
parent3d3653f9732c73feb8c4addfc1cbdaa292a399fa (diff)
ipc/shm: remove special shm_alloc/free
There is nothing special about the shm_alloc/free routines any more, so remove them to make code more readable. [manfred@colorfullife.com: Rediff, to continue to keep rcu for free calls after a successful security_shm_alloc()] Link: http://lkml.kernel.org/r/20170525185107.12869-18-manfred@colorfullife.com Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Manfred Spraul <manfred@colorfullife.com> Cc: Davidlohr Bueso <dave@stgolabs.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'ipc/shm.c')
-rw-r--r--ipc/shm.c24
1 files changed, 4 insertions, 20 deletions
diff --git a/ipc/shm.c b/ipc/shm.c
index d1988ef821a1..28a444861a8f 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -172,11 +172,6 @@ static inline void shm_lock_by_ptr(struct shmid_kernel *ipcp)
172 ipc_lock_object(&ipcp->shm_perm); 172 ipc_lock_object(&ipcp->shm_perm);
173} 173}
174 174
175static void __shm_free(struct shmid_kernel *shp)
176{
177 kvfree(shp);
178}
179
180static void shm_rcu_free(struct rcu_head *head) 175static void shm_rcu_free(struct rcu_head *head)
181{ 176{
182 struct kern_ipc_perm *ptr = container_of(head, struct kern_ipc_perm, 177 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)
184 struct shmid_kernel *shp = container_of(ptr, struct shmid_kernel, 179 struct shmid_kernel *shp = container_of(ptr, struct shmid_kernel,
185 shm_perm); 180 shm_perm);
186 security_shm_free(shp); 181 security_shm_free(shp);
187 __shm_free(shp); 182 kvfree(shp);
188} 183}
189 184
190static inline void shm_rmid(struct ipc_namespace *ns, struct shmid_kernel *s) 185static 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 = {
518#endif 513#endif
519}; 514};
520 515
521static struct shmid_kernel *shm_alloc(void)
522{
523 struct shmid_kernel *shp;
524
525 shp = kvmalloc(sizeof(*shp), GFP_KERNEL);
526 if (unlikely(!shp))
527 return NULL;
528
529 return shp;
530}
531
532/** 516/**
533 * newseg - Create a new shared memory segment 517 * newseg - Create a new shared memory segment
534 * @ns: namespace 518 * @ns: namespace
@@ -558,8 +542,8 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
558 ns->shm_tot + numpages > ns->shm_ctlall) 542 ns->shm_tot + numpages > ns->shm_ctlall)
559 return -ENOSPC; 543 return -ENOSPC;
560 544
561 shp = shm_alloc(); 545 shp = kvmalloc(sizeof(*shp), GFP_KERNEL);
562 if (!shp) 546 if (unlikely(!shp))
563 return -ENOMEM; 547 return -ENOMEM;
564 548
565 shp->shm_perm.key = key; 549 shp->shm_perm.key = key;
@@ -569,7 +553,7 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
569 shp->shm_perm.security = NULL; 553 shp->shm_perm.security = NULL;
570 error = security_shm_alloc(shp); 554 error = security_shm_alloc(shp);
571 if (error) { 555 if (error) {
572 __shm_free(shp); 556 kvfree(shp);
573 return error; 557 return error;
574 } 558 }
575 559