pinctrl: at91-pio4: add missing of_node_put
[linux-2.6-block.git] / kernel / utsname.c
index 6976cd47dcf6028270eee444228eca7a340ca2d2..dcd6be1996fe7ffcdb2dd0d15d516ffaea52df4b 100644 (file)
 #include <linux/utsname.h>
 #include <linux/err.h>
 #include <linux/slab.h>
+#include <linux/cred.h>
 #include <linux/user_namespace.h>
 #include <linux/proc_ns.h>
+#include <linux/sched/task.h>
+
+static struct kmem_cache *uts_ns_cache __ro_after_init;
 
 static struct ucounts *inc_uts_namespaces(struct user_namespace *ns)
 {
@@ -31,7 +35,7 @@ static struct uts_namespace *create_uts_ns(void)
 {
        struct uts_namespace *uts_ns;
 
-       uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
+       uts_ns = kmem_cache_alloc(uts_ns_cache, GFP_KERNEL);
        if (uts_ns)
                kref_init(&uts_ns->kref);
        return uts_ns;
@@ -40,7 +44,7 @@ static struct uts_namespace *create_uts_ns(void)
 /*
  * Clone a new ns copying an original utsname, setting refcount to 1
  * @old_ns: namespace to clone
- * Return ERR_PTR(-ENOMEM) on error (failure to kmalloc), new ns otherwise
+ * Return ERR_PTR(-ENOMEM) on error (failure to allocate), new ns otherwise
  */
 static struct uts_namespace *clone_uts_ns(struct user_namespace *user_ns,
                                          struct uts_namespace *old_ns)
@@ -73,7 +77,7 @@ static struct uts_namespace *clone_uts_ns(struct user_namespace *user_ns,
        return ns;
 
 fail_free:
-       kfree(ns);
+       kmem_cache_free(uts_ns_cache, ns);
 fail_dec:
        dec_uts_namespaces(ucounts);
 fail:
@@ -111,7 +115,7 @@ void free_uts_ns(struct kref *kref)
        dec_uts_namespaces(ns->ucounts);
        put_user_ns(ns->user_ns);
        ns_free_inum(&ns->ns);
-       kfree(ns);
+       kmem_cache_free(uts_ns_cache, ns);
 }
 
 static inline struct uts_namespace *to_uts_ns(struct ns_common *ns)
@@ -167,3 +171,13 @@ const struct proc_ns_operations utsns_operations = {
        .install        = utsns_install,
        .owner          = utsns_owner,
 };
+
+void __init uts_ns_init(void)
+{
+       uts_ns_cache = kmem_cache_create_usercopy(
+                       "uts_namespace", sizeof(struct uts_namespace), 0,
+                       SLAB_PANIC|SLAB_ACCOUNT,
+                       offsetof(struct uts_namespace, name),
+                       sizeof_field(struct uts_namespace, name),
+                       NULL);
+}