From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755056Ab3A2TKb (ORCPT ); Tue, 29 Jan 2013 14:10:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45379 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754387Ab3A2TIF (ORCPT ); Tue, 29 Jan 2013 14:08:05 -0500 Message-Id: <20130129190759.567563910@napanee.usersys.redhat.com> User-Agent: quilt/0.48-1 Date: Tue, 29 Jan 2013 14:08:01 -0500 From: aris@redhat.com To: linux-kernel@vger.kernel.org Cc: cgroups@vger.kernel.org, Tejun Heo , Serge Hallyn Subject: [PATCH v3 2/9] devcg: reorder device exception functions References: <20130129190759.117458287@napanee.usersys.redhat.com> Content-Disposition: inline; filename=reorder_exception_functions.patch Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation for the next patch, reorder dev_exception_add() and dev_exception_rm(). Cc: Tejun Heo Cc: Serge Hallyn Signed-off-by: Aristeu Rozanski --- security/device_cgroup.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) --- github.orig/security/device_cgroup.c 2013-01-29 11:49:14.739657516 -0500 +++ github/security/device_cgroup.c 2013-01-29 11:49:14.987661210 -0500 @@ -104,18 +104,14 @@ free_and_exit: /* * called under devcgroup_mutex */ -static int dev_exception_add(struct list_head *exceptions, +static void dev_exception_rm(struct list_head *exceptions, struct dev_exception_item *ex) { - struct dev_exception_item *excopy, *walk; + struct dev_exception_item *walk, *tmp; lockdep_assert_held(&devcgroup_mutex); - excopy = kmemdup(ex, sizeof(*ex), GFP_KERNEL); - if (!excopy) - return -ENOMEM; - - list_for_each_entry(walk, exceptions, list) { + list_for_each_entry_safe(walk, tmp, exceptions, list) { if (walk->type != ex->type) continue; if (walk->major != ex->major) @@ -123,27 +119,29 @@ static int dev_exception_add(struct list if (walk->minor != ex->minor) continue; - walk->access |= ex->access; - kfree(excopy); - excopy = NULL; + walk->access &= ~ex->access; + if (!walk->access) { + list_del_rcu(&walk->list); + kfree_rcu(walk, rcu); + } } - - if (excopy != NULL) - list_add_tail_rcu(&excopy->list, exceptions); - return 0; } /* * called under devcgroup_mutex */ -static void dev_exception_rm(struct list_head *exceptions, +static int dev_exception_add(struct list_head *exceptions, struct dev_exception_item *ex) { - struct dev_exception_item *walk, *tmp; + struct dev_exception_item *excopy, *walk; lockdep_assert_held(&devcgroup_mutex); - list_for_each_entry_safe(walk, tmp, exceptions, list) { + excopy = kmemdup(ex, sizeof(*ex), GFP_KERNEL); + if (!excopy) + return -ENOMEM; + + list_for_each_entry(walk, exceptions, list) { if (walk->type != ex->type) continue; if (walk->major != ex->major) @@ -151,12 +149,14 @@ static void dev_exception_rm(struct list if (walk->minor != ex->minor) continue; - walk->access &= ~ex->access; - if (!walk->access) { - list_del_rcu(&walk->list); - kfree_rcu(walk, rcu); - } + walk->access |= ex->access; + kfree(excopy); + excopy = NULL; } + + if (excopy != NULL) + list_add_tail_rcu(&excopy->list, exceptions); + return 0; } static void __dev_exception_clean(struct dev_cgroup *dev_cgroup)