lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <b4393af3-d2ec-85b5-4be8-d5abd8847499@quicinc.com>
Date:   Thu, 16 Jun 2022 18:43:24 +0530
From:   Mukesh Ojha <quic_mojha@...cinc.com>
To:     Lin Feng <linf@...gsu.com>, <tj@...nel.org>,
        <lizefan.x@...edance.com>, <hannes@...xchg.org>
CC:     <cgroups@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] cgroup.c: add helper __cset_cgroup_from_root to cleanup
 duplicated codes

Hi,

On 6/16/2022 4:08 PM, Lin Feng wrote:
> No funtionality change, but save us some lines.
> 
> Signed-off-by: Lin Feng <linf@...gsu.com>
> ---
>   kernel/cgroup/cgroup.c | 58 ++++++++++++++++++++----------------------
>   1 file changed, 27 insertions(+), 31 deletions(-)
> 
> diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
> index 1779ccddb734..a8a46eb66f21 100644
> --- a/kernel/cgroup/cgroup.c
> +++ b/kernel/cgroup/cgroup.c
> @@ -1376,6 +1376,31 @@ static void cgroup_destroy_root(struct cgroup_root *root)
>   	cgroup_free_root(root);
>   }
>   
> +static inline struct cgroup *__cset_cgroup_from_root(struct css_set *cset,
> +					    struct cgroup_root *root)
> +{
> +	struct cgroup *res_cgroup = NULL;
> +
> +	if (cset == &init_css_set) {
> +		res_cgroup = &root->cgrp;
> +	} else if (root == &cgrp_dfl_root) {
> +		res_cgroup = cset->dfl_cgrp;
> +	} else {
> +		struct cgrp_cset_link *link;
> +
> +		list_for_each_entry(link, &cset->cgrp_links, cgrp_link) {
> +			struct cgroup *c = link->cgrp;
> +
> +			if (c->root == root) {
> +				res_cgroup = c;
> +				break;
> +			}
> +		}
> +	}
> +
> +	return res_cgroup;
> +}
> +
>   /*
>    * look up cgroup associated with current task's cgroup namespace on the
>    * specified hierarchy
> @@ -1391,22 +1416,8 @@ current_cgns_cgroup_from_root(struct cgroup_root *root)
>   	rcu_read_lock();
>   
>   	cset = current->nsproxy->cgroup_ns->root_cset;
> -	if (cset == &init_css_set) {
> -		res = &root->cgrp;
> -	} else if (root == &cgrp_dfl_root) {
> -		res = cset->dfl_cgrp;
> -	} else {
> -		struct cgrp_cset_link *link;
> -
> -		list_for_each_entry(link, &cset->cgrp_links, cgrp_link) {
> -			struct cgroup *c = link->cgrp;
> +	res = __cset_cgroup_from_root(cset, root);
>   
> -			if (c->root == root) {
> -				res = c;
> -				break;
> -			}
> -		}
> -	}
>   	rcu_read_unlock();
>   
>   	BUG_ON(!res);
> @@ -1422,22 +1433,7 @@ static struct cgroup *cset_cgroup_from_root(struct css_set *cset,
>   	lockdep_assert_held(&cgroup_mutex);
>   	lockdep_assert_held(&css_set_lock);
>   
> -	if (cset == &init_css_set) {
> -		res = &root->cgrp;
> -	} else if (root == &cgrp_dfl_root) {
> -		res = cset->dfl_cgrp;
> -	} else {
> -		struct cgrp_cset_link *link;
> -
> -		list_for_each_entry(link, &cset->cgrp_links, cgrp_link) {
> -			struct cgroup *c = link->cgrp;
> -
> -			if (c->root == root) {
> -				res = c;
> -				break;
> -			}
> -		}
> -	}
> +	res = __cset_cgroup_from_root(cset, root);
>   
>   	BUG_ON(!res);
>   	return res;


Thanks for the patch
Liked the idea.

Acked-by: Mukesh Ojha <quic_mojha@...cinc.com>

-Mukesh

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ