]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - ipc/util.c
x86: provide an init_mem_mapping hypervisor hook
[karo-tx-linux.git] / ipc / util.c
index caec7b1bfaa335f3d6df017eb9b0ad24058edd9c..1a2cb02467ab5f33f309a4542620cbec8d18361a 100644 (file)
@@ -232,6 +232,7 @@ int ipc_addid(struct ipc_ids *ids, struct kern_ipc_perm *new, int size)
 
        idr_preload(GFP_KERNEL);
 
+       atomic_set(&new->refcount, 1);
        spin_lock_init(&new->lock);
        new->deleted = false;
        rcu_read_lock();
@@ -394,70 +395,18 @@ void ipc_rmid(struct ipc_ids *ids, struct kern_ipc_perm *ipcp)
        ipcp->deleted = true;
 }
 
-/**
- * ipc_alloc - allocate ipc space
- * @size: size desired
- *
- * Allocate memory from the appropriate pools and return a pointer to it.
- * NULL is returned if the allocation fails
- */
-void *ipc_alloc(int size)
-{
-       return kvmalloc(size, GFP_KERNEL);
-}
-
-/**
- * ipc_free - free ipc space
- * @ptr: pointer returned by ipc_alloc
- *
- * Free a block created with ipc_alloc().
- */
-void ipc_free(void *ptr)
+int ipc_rcu_getref(struct kern_ipc_perm *ptr)
 {
-       kvfree(ptr);
+       return atomic_inc_not_zero(&ptr->refcount);
 }
 
-/**
- * ipc_rcu_alloc - allocate ipc and rcu space
- * @size: size desired
- *
- * Allocate memory for the rcu header structure +  the object.
- * Returns the pointer to the object or NULL upon failure.
- */
-void *ipc_rcu_alloc(int size)
+void ipc_rcu_putref(struct kern_ipc_perm *ptr,
+                       void (*func)(struct rcu_head *head))
 {
-       /*
-        * We prepend the allocation with the rcu struct
-        */
-       struct ipc_rcu *out = ipc_alloc(sizeof(struct ipc_rcu) + size);
-       if (unlikely(!out))
-               return NULL;
-       atomic_set(&out->refcount, 1);
-       return out + 1;
-}
-
-int ipc_rcu_getref(void *ptr)
-{
-       struct ipc_rcu *p = ((struct ipc_rcu *)ptr) - 1;
-
-       return atomic_inc_not_zero(&p->refcount);
-}
-
-void ipc_rcu_putref(void *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);
-}
-
-void ipc_rcu_free(struct rcu_head *head)
-{
-       struct ipc_rcu *p = container_of(head, struct ipc_rcu, rcu);
-
-       kvfree(p);
+       call_rcu(&ptr->rcu, func);
 }
 
 /**