cgroup: Remove unnecessary call to strstrip()
PATCH 1/1 cgroup: Remove unnecessary call to strstrip()
The string buf will be stripped in cgroup_procs_write_start() before it is converted to int, so remove this unnecessary call to strstrip().
--- kernel/cgroup/cgroup.c | 2 -- 1 file changed, 2 deletions(-)
kernel/cgroup/cgroup.c +0 -2
@@ -4774,8 +4774,6 @@ static ssize_t cgroup_threads_write(struct kernfs_open_file *of,ssize_t ret;bool locked; - buf =strstrip (buf); - dst_cgrp =cgroup_kn_lock_live (of->kn, false);if (!dst_cgrp)return -ENODEV ;
Signature · 1 line
2.24.1
Michal Koutný
maintainerHello.
Quoted 2 lines · Hao Lee
The string buf will be stripped in
cgroup_procs_write_start()before it is converted to int, so remove this unnecessary call tostrstrip().
Good catch, Hao.
Perhaps the code be then simplified a bit
-- >8 --
From: =?UTF-8?q?Michal=20Koutn=C3=BD?= <mkoutny-IBi9RG/[email protected]>
Date: Thu, 14 Jan 2021 13:23:39 +0100
Subject: [PATCH] cgroup: cgroup.{procs,threads} factor out common parts
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The functions cgroup_threads_start and cgroup_procs_start are almost identical. In order to reduce duplication, factor out the common code in similar fashion we already do for other threadgroup/task functions. No functional changes are intended.
--- kernel/cgroup/cgroup.c | 55 +++++++++++------------------------------- 1 file changed, 14 insertions(+), 41 deletions(-)
kernel/cgroup/cgroup.c +14 -41
@@ -4726,8 +4726,8 @@ static int cgroup_attach_permissions(struct cgroup *src_cgrp,return ret; } -static ssize_t cgroup_procs_write (struct kernfs_open_file *of, -char *buf,size_t nbytes,loff_t off) +static ssize_t __cgroup_procs_write (struct kernfs_open_file *of,char *buf, +bool threadgroup) {struct cgroup *src_cgrp, *dst_cgrp;struct task_struct *task;
@@ -4738,7 +4738,7 @@ static ssize_t cgroup_procs_write(struct kernfs_open_file *of,if (!dst_cgrp)return -ENODEV ; - task =cgroup_procs_write_start (buf, true, &locked); + task =cgroup_procs_write_start (buf, threadgroup, &locked); ret =PTR_ERR_OR_ZERO (task);if (ret) goto out_unlock;
@@ -4748,19 +4748,26 @@ static ssize_t cgroup_procs_write(struct kernfs_open_file *of, src_cgrp =task_cgroup_from_root (task, &cgrp_dfl_root);spin_unlock_irq (&css_set_lock); +/* process and thread migrations follow same delegation rule */ ret =cgroup_attach_permissions (src_cgrp, dst_cgrp, - of->file->f_path.dentry->d_sb, true); + of->file->f_path.dentry->d_sb, threadgroup);if (ret) goto out_finish; - ret =cgroup_attach_task (dst_cgrp, task, true); + ret =cgroup_attach_task (dst_cgrp, task, threadgroup); out_finish:cgroup_procs_write_finish (task, locked); out_unlock:cgroup_kn_unlock (of->kn); -return ret ?: nbytes; +return ret; +} + +static ssize_t cgroup_procs_write (struct kernfs_open_file *of, +char *buf,size_t nbytes,loff_t off) +{ +return __cgroup_procs_write (of, buf, true) ?: nbytes; }static void *cgroup_threads_start (struct seq_file *s,loff_t *pos)
@@ -4771,41 +4778,7 @@ static void *cgroup_threads_start(struct seq_file *s, loff_t *pos)static ssize_t cgroup_threads_write (struct kernfs_open_file *of,char *buf,size_t nbytes,loff_t off) { -struct cgroup *src_cgrp, *dst_cgrp; -struct task_struct *task; -ssize_t ret; -bool locked; - - buf =strstrip (buf); - - dst_cgrp =cgroup_kn_lock_live (of->kn, false); -if (!dst_cgrp) -return -ENODEV ; - - task =cgroup_procs_write_start (buf, false, &locked); - ret =PTR_ERR_OR_ZERO (task); -if (ret) - goto out_unlock; - -/* find the source cgroup */ -spin_lock_irq (&css_set_lock); - src_cgrp =task_cgroup_from_root (task, &cgrp_dfl_root); -spin_unlock_irq (&css_set_lock); - -/* thread migrations follow the cgroup.procs delegation rule */ - ret =cgroup_attach_permissions (src_cgrp, dst_cgrp, - of->file->f_path.dentry->d_sb, false); -if (ret) - goto out_finish; - - ret =cgroup_attach_task (dst_cgrp, task, false); - -out_finish: -cgroup_procs_write_finish (task, locked); -out_unlock: -cgroup_kn_unlock (of->kn); - -return ret ?: nbytes; +return __cgroup_procs_write (of, buf, false) ?: nbytes; }/* cgroup core interface files for the default hierarchy */
Signature · 1 line
2.29.2
Daniel Jordan
Reviewed-byHello Michal,
Quoted 15 lines · Michal Koutný
Quoted 2 lines · Hao Lee
The string buf will be stripped in
cgroup_procs_write_start()before it is converted to int, so remove this unnecessary call tostrstrip().Good catch, Hao.
Perhaps the code be then simplified a bit
-- >8 --
From: =?UTF-8?q?Michal=20Koutn=C3=BD?= <mkoutny-IBi9RG/[email protected]>
Date: Thu, 14 Jan 2021 13:23:39 +0100
Subject: [PATCH] cgroup: cgroup.{procs,threads} factor out common parts
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Quoted 1 line
The functions
cgroup_threads_startandcgroup_procs_startare almost
You meant cgroup_threads_write and cgroup_procs_write.
Quoted 2 lines
kernel/cgroup/cgroup.c | 55 +++++++++++------------------------------- 1 file changed, 14 insertions(+), 41 deletions(-)
Ok, sure, that's a good thing.
Quoted 10 lines
Perhaps the code be then simplified a bit
-- >8 --
From: =?UTF-8?q?Michal=20Koutn=C3=BD?= <mkoutny-IBi9RG/[email protected]>
Date: Thu, 14 Jan 2021 13:23:39 +0100
Subject: [PATCH] cgroup: cgroup.{procs,threads} factor out common parts
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Quoted 4 lines
The functions
cgroup_threads_startandcgroup_procs_startare almost identical. In order to reduce duplication, factor out the common code in similar fashion we already do for other threadgroup/task functions. No functional changes are intended.
Nice work. I didn't realize this simplification :)
Regards,
Hao Lee
Quoted 17 lines · Michal Koutný
Hello.
Quoted 2 lines · Hao Lee
The string buf will be stripped in
cgroup_procs_write_start()before it is converted to int, so remove this unnecessary call tostrstrip().Good catch, Hao.
Perhaps the code be then simplified a bit
-- >8 --
From: =?UTF-8?q?Michal=20Koutn=C3=BD?= <mkoutny-IBi9RG/[email protected]>
Date: Thu, 14 Jan 2021 13:23:39 +0100
Subject: [PATCH] cgroup: cgroup.{procs,threads} factor out common parts
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Quoted 7 lines
The functions
cgroup_threads_startandcgroup_procs_startare almost identical. In order to reduce duplication, factor out the common code in similar fashion we already do for other threadgroup/task functions. No functional changes are intended.Suggested-by Hao Lee <[email protected]>Signed-off-by Michal Koutný <mkoutny-IBi9RG/[email protected]>
Applied to cgroup/for-5.12 w/ minor description update suggested by Daniel.
Thanks.
Signature · 1 line
tejun