]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - ipc/util.c
ipc: merge ipc_rcu and kern_ipc_perm
[mirror_ubuntu-artful-kernel.git] / ipc / util.c
index caec7b1bfaa335f3d6df017eb9b0ad24058edd9c..5d1ff1035efe308651b35162983b28ca76e45dd2 100644 (file)
@@ -418,46 +418,45 @@ void ipc_free(void *ptr)
 }
 
 /**
- * ipc_rcu_alloc - allocate ipc and rcu space
+ * ipc_rcu_alloc - allocate ipc space
  * @size: size desired
  *
- * Allocate memory for the rcu header structure +  the object.
- * Returns the pointer to the object or NULL upon failure.
+ * Allocate memory for an ipc object.
+ * The first member must be struct kern_ipc_perm.
  */
-void *ipc_rcu_alloc(int size)
+struct kern_ipc_perm *ipc_rcu_alloc(int size)
 {
        /*
         * We prepend the allocation with the rcu struct
         */
-       struct ipc_rcu *out = ipc_alloc(sizeof(struct ipc_rcu) + size);
+       struct kern_ipc_perm *out = ipc_alloc(size);
        if (unlikely(!out))
                return NULL;
+
+       memset(out, 0, size);
        atomic_set(&out->refcount, 1);
-       return out + 1;
+       return out;
 }
 
-int ipc_rcu_getref(void *ptr)
+int ipc_rcu_getref(struct kern_ipc_perm *ptr)
 {
-       struct ipc_rcu *p = ((struct ipc_rcu *)ptr) - 1;
-
-       return atomic_inc_not_zero(&p->refcount);
+       return atomic_inc_not_zero(&ptr->refcount);
 }
 
-void ipc_rcu_putref(void *ptr, void (*func)(struct rcu_head *head))
+void ipc_rcu_putref(struct kern_ipc_perm *ptr,
+                       void (*func)(struct rcu_head *head))
 {
-       struct ipc_rcu *p = ((struct ipc_rcu *)ptr) - 1;
-
-       if (!atomic_dec_and_test(&p->refcount))
+       if (!atomic_dec_and_test(&ptr->refcount))
                return;
 
-       call_rcu(&p->rcu, func);
+       call_rcu(&ptr->rcu, func);
 }
 
-void ipc_rcu_free(struct rcu_head *head)
+void ipc_rcu_free(struct rcu_head *h)
 {
-       struct ipc_rcu *p = container_of(head, struct ipc_rcu, rcu);
+       struct kern_ipc_perm *ptr = container_of(h, struct kern_ipc_perm, rcu);
 
-       kvfree(p);
+       kvfree(ptr);
 }
 
 /**