]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - ipc/shm.c
Merge branch 'locking-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[karo-tx-linux.git] / ipc / shm.c
index 566c1e193ee13ede1ae80a78f2f9a991af439f01..28a444861a8f489fa46edca81878eedf0f55da7a 100644 (file)
--- 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)
@@ -535,7 +530,6 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
        size_t numpages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
        struct file *file;
        char name[13];
-       int id;
        vm_flags_t acctflag = 0;
 
        if (size < SHMMIN || size > ns->shm_ctlmax)
@@ -548,11 +542,8 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
                        ns->shm_tot + numpages > ns->shm_ctlall)
                return -ENOSPC;
 
-       BUILD_BUG_ON(offsetof(struct shmid_kernel, shm_perm) != 0);
-
-       shp = container_of(ipc_rcu_alloc(sizeof(*shp)), struct shmid_kernel,
-                               shm_perm);
-       if (!shp)
+       shp = kvmalloc(sizeof(*shp), GFP_KERNEL);
+       if (unlikely(!shp))
                return -ENOMEM;
 
        shp->shm_perm.key = key;
@@ -562,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;
        }
 
@@ -607,11 +598,9 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
        shp->shm_file = file;
        shp->shm_creator = current;
 
-       id = ipc_addid(&shm_ids(ns), &shp->shm_perm, ns->shm_ctlmni);
-       if (id < 0) {
-               error = id;
+       error = ipc_addid(&shm_ids(ns), &shp->shm_perm, ns->shm_ctlmni);
+       if (error < 0)
                goto no_id;
-       }
 
        list_add(&shp->shm_clist, &current->sysvshm.shm_clist);
 
@@ -633,7 +622,7 @@ no_id:
                user_shm_unlock(size, shp->mlock_user);
        fput(file);
 no_file:
-       ipc_rcu_putref(&shp->shm_perm, shm_rcu_free);
+       call_rcu(&shp->shm_perm.rcu, shm_rcu_free);
        return error;
 }