]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - security/device_cgroup.c
perf sort: Align cpu column to right
[karo-tx-linux.git] / security / device_cgroup.c
index b08d20c66c2e17e0fa8333984df8eb4a82595e0b..d794abcc4b3b7e5e87173ba8ca45deca5b6d09d8 100644 (file)
@@ -82,6 +82,8 @@ static int dev_exceptions_copy(struct list_head *dest, struct list_head *orig)
 {
        struct dev_exception_item *ex, *tmp, *new;
 
+       lockdep_assert_held(&devcgroup_mutex);
+
        list_for_each_entry(ex, orig, list) {
                new = kmemdup(ex, sizeof(*ex), GFP_KERNEL);
                if (!new)
@@ -107,6 +109,8 @@ static int dev_exception_add(struct dev_cgroup *dev_cgroup,
 {
        struct dev_exception_item *excopy, *walk;
 
+       lockdep_assert_held(&devcgroup_mutex);
+
        excopy = kmemdup(ex, sizeof(*ex), GFP_KERNEL);
        if (!excopy)
                return -ENOMEM;
@@ -137,6 +141,8 @@ static void dev_exception_rm(struct dev_cgroup *dev_cgroup,
 {
        struct dev_exception_item *walk, *tmp;
 
+       lockdep_assert_held(&devcgroup_mutex);
+
        list_for_each_entry_safe(walk, tmp, &dev_cgroup->exceptions, list) {
                if (walk->type != ex->type)
                        continue;
@@ -163,6 +169,8 @@ static void dev_exception_clean(struct dev_cgroup *dev_cgroup)
 {
        struct dev_exception_item *ex, *tmp;
 
+       lockdep_assert_held(&devcgroup_mutex);
+
        list_for_each_entry_safe(ex, tmp, &dev_cgroup->exceptions, list) {
                list_del_rcu(&ex->list);
                kfree_rcu(ex, rcu);
@@ -172,7 +180,7 @@ static void dev_exception_clean(struct dev_cgroup *dev_cgroup)
 /*
  * called from kernel/cgroup.c with cgroup_lock() held.
  */
-static struct cgroup_subsys_state *devcgroup_create(struct cgroup *cgroup)
+static struct cgroup_subsys_state *devcgroup_css_alloc(struct cgroup *cgroup)
 {
        struct dev_cgroup *dev_cgroup, *parent_dev_cgroup;
        struct cgroup *parent_cgroup;
@@ -202,12 +210,14 @@ static struct cgroup_subsys_state *devcgroup_create(struct cgroup *cgroup)
        return &dev_cgroup->css;
 }
 
-static void devcgroup_destroy(struct cgroup *cgroup)
+static void devcgroup_css_free(struct cgroup *cgroup)
 {
        struct dev_cgroup *dev_cgroup;
 
        dev_cgroup = cgroup_to_devcgroup(cgroup);
+       mutex_lock(&devcgroup_mutex);
        dev_exception_clean(dev_cgroup);
+       mutex_unlock(&devcgroup_mutex);
        kfree(dev_cgroup);
 }
 
@@ -298,6 +308,10 @@ static int may_access(struct dev_cgroup *dev_cgroup,
        struct dev_exception_item *ex;
        bool match = false;
 
+       rcu_lockdep_assert(rcu_read_lock_held() ||
+                          lockdep_is_held(&devcgroup_mutex),
+                          "device_cgroup::may_access() called without proper synchronization");
+
        list_for_each_entry_rcu(ex, &dev_cgroup->exceptions, list) {
                if ((refex->type & DEV_BLOCK) && !(ex->type & DEV_BLOCK))
                        continue;
@@ -552,8 +566,8 @@ static struct cftype dev_cgroup_files[] = {
 struct cgroup_subsys devices_subsys = {
        .name = "devices",
        .can_attach = devcgroup_can_attach,
-       .create = devcgroup_create,
-       .destroy = devcgroup_destroy,
+       .css_alloc = devcgroup_css_alloc,
+       .css_free = devcgroup_css_free,
        .subsys_id = devices_subsys_id,
        .base_cftypes = dev_cgroup_files,