Skip to content

Commit

Permalink
devscgroup: relax task to dev_cgroup conversion
Browse files Browse the repository at this point in the history
Two functions, that need to get a device_cgroup from a task (they are
devcgroup_inode_permission and devcgroup_inode_mknod) make it in a strange
way:

They get a css_set from task, then a subsys_state from css_set, then a
cgroup from the state and then a subsys_state again from the cgroup.
Besides, the devices_subsys_id is read from memory, whilst there's a
enum-ed constant for it.

Optimize this part a bit:
1. Get the subsys_stats form the task and be done - no 2 extra
   dereferences,
2. Use the device_subsys_id constant, not the value from memory
   (i.e. one less dereference).

Found while preparing 2.6.26 OpenVZ port.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Acked-by: Paul Menage <menage@google.com>
Cc: Balbir Singh <balbir@in.ibm.com>
Cc: James Morris <jmorris@namei.org>
Cc: Chris Wright <chrisw@sous-sol.org>
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Pavel Emelyanov authored and Linus Torvalds committed Jun 6, 2008
1 parent b66862f commit cc9cb21
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions security/device_cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ struct cgroup_subsys devices_subsys = {

int devcgroup_inode_permission(struct inode *inode, int mask)
{
struct cgroup *cgroup;
struct dev_cgroup *dev_cgroup;
struct dev_whitelist_item *wh;

Expand All @@ -515,8 +514,8 @@ int devcgroup_inode_permission(struct inode *inode, int mask)
return 0;
if (!S_ISBLK(inode->i_mode) && !S_ISCHR(inode->i_mode))
return 0;
cgroup = task_cgroup(current, devices_subsys.subsys_id);
dev_cgroup = cgroup_to_devcgroup(cgroup);
dev_cgroup = css_to_devcgroup(task_subsys_state(current,
devices_subsys_id));
if (!dev_cgroup)
return 0;

Expand Down Expand Up @@ -547,12 +546,11 @@ int devcgroup_inode_permission(struct inode *inode, int mask)

int devcgroup_inode_mknod(int mode, dev_t dev)
{
struct cgroup *cgroup;
struct dev_cgroup *dev_cgroup;
struct dev_whitelist_item *wh;

cgroup = task_cgroup(current, devices_subsys.subsys_id);
dev_cgroup = cgroup_to_devcgroup(cgroup);
dev_cgroup = css_to_devcgroup(task_subsys_state(current,
devices_subsys_id));
if (!dev_cgroup)
return 0;

Expand Down

0 comments on commit cc9cb21

Please sign in to comment.