libata: pata_pdc2027x PLL input clock fix
[sfrench/cifs-2.6.git] / ipc / util.c
index 0c97cb746160980733569830b1944451f9d33a22..7536a7292d4821ae7b64b4f79f6f32f6657c40da 100644 (file)
@@ -21,7 +21,6 @@
 #include <linux/shm.h>
 #include <linux/init.h>
 #include <linux/msg.h>
-#include <linux/smp_lock.h>
 #include <linux/vmalloc.h>
 #include <linux/slab.h>
 #include <linux/capability.h>
@@ -85,53 +84,20 @@ err_mem:
        return ERR_PTR(err);
 }
 
-int unshare_ipcs(unsigned long unshare_flags, struct ipc_namespace **new_ipc)
+struct ipc_namespace *copy_ipcs(unsigned long flags, struct ipc_namespace *ns)
 {
-       struct ipc_namespace *new;
-
-       if (unshare_flags & CLONE_NEWIPC) {
-               if (!capable(CAP_SYS_ADMIN))
-                       return -EPERM;
-
-               new = clone_ipc_ns(current->nsproxy->ipc_ns);
-               if (IS_ERR(new))
-                       return PTR_ERR(new);
-
-               *new_ipc = new;
-       }
-
-       return 0;
-}
-
-int copy_ipcs(unsigned long flags, struct task_struct *tsk)
-{
-       struct ipc_namespace *old_ns = tsk->nsproxy->ipc_ns;
        struct ipc_namespace *new_ns;
-       int err = 0;
 
-       if (!old_ns)
-               return 0;
-
-       get_ipc_ns(old_ns);
+       BUG_ON(!ns);
+       get_ipc_ns(ns);
 
        if (!(flags & CLONE_NEWIPC))
-               return 0;
-
-       if (!capable(CAP_SYS_ADMIN)) {
-               err = -EPERM;
-               goto out;
-       }
+               return ns;
 
-       new_ns = clone_ipc_ns(old_ns);
-       if (!new_ns) {
-               err = -ENOMEM;
-               goto out;
-       }
+       new_ns = clone_ipc_ns(ns);
 
-       tsk->nsproxy->ipc_ns = new_ns;
-out:
-       put_ipc_ns(old_ns);
-       return err;
+       put_ipc_ns(ns);
+       return new_ns;
 }
 
 void free_ipc_ns(struct kref *kref)
@@ -144,6 +110,13 @@ void free_ipc_ns(struct kref *kref)
        shm_exit_ns(ns);
        kfree(ns);
 }
+#else
+struct ipc_namespace *copy_ipcs(unsigned long flags, struct ipc_namespace *ns)
+{
+       if (flags & CLONE_NEWIPC)
+               return ERR_PTR(-EINVAL);
+       return ns;
+}
 #endif
 
 /**
@@ -205,7 +178,7 @@ void __ipc_init ipc_init_ids(struct ipc_ids* ids, int size)
 }
 
 #ifdef CONFIG_PROC_FS
-static struct file_operations sysvipc_proc_fops;
+static const struct file_operations sysvipc_proc_fops;
 /**
  *     ipc_init_proc_interface -  Create a proc interface for sysipc types using a seq_file interface.
  *     @path: Path in procfs
@@ -738,14 +711,20 @@ int ipc_parse_version (int *cmd)
 #endif /* __ARCH_WANT_IPC_PARSE_VERSION */
 
 #ifdef CONFIG_PROC_FS
+struct ipc_proc_iter {
+       struct ipc_namespace *ns;
+       struct ipc_proc_iface *iface;
+};
+
 static void *sysvipc_proc_next(struct seq_file *s, void *it, loff_t *pos)
 {
-       struct ipc_proc_iface *iface = s->private;
+       struct ipc_proc_iter *iter = s->private;
+       struct ipc_proc_iface *iface = iter->iface;
        struct kern_ipc_perm *ipc = it;
        loff_t p;
        struct ipc_ids *ids;
 
-       ids = current->nsproxy->ipc_ns->ids[iface->ids];
+       ids = iter->ns->ids[iface->ids];
 
        /* If we had an ipc id locked before, unlock it */
        if (ipc && ipc != SEQ_START_TOKEN)
@@ -772,12 +751,13 @@ static void *sysvipc_proc_next(struct seq_file *s, void *it, loff_t *pos)
  */
 static void *sysvipc_proc_start(struct seq_file *s, loff_t *pos)
 {
-       struct ipc_proc_iface *iface = s->private;
+       struct ipc_proc_iter *iter = s->private;
+       struct ipc_proc_iface *iface = iter->iface;
        struct kern_ipc_perm *ipc;
        loff_t p;
        struct ipc_ids *ids;
 
-       ids = current->nsproxy->ipc_ns->ids[iface->ids];
+       ids = iter->ns->ids[iface->ids];
 
        /*
         * Take the lock - this will be released by the corresponding
@@ -806,21 +786,23 @@ static void *sysvipc_proc_start(struct seq_file *s, loff_t *pos)
 static void sysvipc_proc_stop(struct seq_file *s, void *it)
 {
        struct kern_ipc_perm *ipc = it;
-       struct ipc_proc_iface *iface = s->private;
+       struct ipc_proc_iter *iter = s->private;
+       struct ipc_proc_iface *iface = iter->iface;
        struct ipc_ids *ids;
 
        /* If we had a locked segment, release it */
        if (ipc && ipc != SEQ_START_TOKEN)
                ipc_unlock(ipc);
 
-       ids = current->nsproxy->ipc_ns->ids[iface->ids];
+       ids = iter->ns->ids[iface->ids];
        /* Release the lock we took in start() */
        mutex_unlock(&ids->mutex);
 }
 
 static int sysvipc_proc_show(struct seq_file *s, void *it)
 {
-       struct ipc_proc_iface *iface = s->private;
+       struct ipc_proc_iter *iter = s->private;
+       struct ipc_proc_iface *iface = iter->iface;
 
        if (it == SEQ_START_TOKEN)
                return seq_puts(s, iface->header);
@@ -835,22 +817,45 @@ static struct seq_operations sysvipc_proc_seqops = {
        .show  = sysvipc_proc_show,
 };
 
-static int sysvipc_proc_open(struct inode *inode, struct file *file) {
+static int sysvipc_proc_open(struct inode *inode, struct file *file)
+{
        int ret;
        struct seq_file *seq;
+       struct ipc_proc_iter *iter;
+
+       ret = -ENOMEM;
+       iter = kmalloc(sizeof(*iter), GFP_KERNEL);
+       if (!iter)
+               goto out;
 
        ret = seq_open(file, &sysvipc_proc_seqops);
-       if (!ret) {
-               seq = file->private_data;
-               seq->private = PDE(inode)->data;
-       }
+       if (ret)
+               goto out_kfree;
+
+       seq = file->private_data;
+       seq->private = iter;
+
+       iter->iface = PDE(inode)->data;
+       iter->ns    = get_ipc_ns(current->nsproxy->ipc_ns);
+out:
        return ret;
+out_kfree:
+       kfree(iter);
+       goto out;
+}
+
+static int sysvipc_proc_release(struct inode *inode, struct file *file)
+{
+       struct seq_file *seq = file->private_data;
+       struct ipc_proc_iter *iter = seq->private;
+       put_ipc_ns(iter->ns);
+       return seq_release_private(inode, file);
 }
 
-static struct file_operations sysvipc_proc_fops = {
+static const struct file_operations sysvipc_proc_fops = {
        .open    = sysvipc_proc_open,
        .read    = seq_read,
        .llseek  = seq_lseek,
-       .release = seq_release,
+       .release = sysvipc_proc_release,
 };
 #endif /* CONFIG_PROC_FS */