From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22AF4C43334 for ; Thu, 16 Jun 2022 13:13:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376405AbiFPNNq (ORCPT ); Thu, 16 Jun 2022 09:13:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376906AbiFPNNd (ORCPT ); Thu, 16 Jun 2022 09:13:33 -0400 Received: from alexa-out-sd-01.qualcomm.com (alexa-out-sd-01.qualcomm.com [199.106.114.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 938352DAA3; Thu, 16 Jun 2022 06:13:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1655385212; x=1686921212; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=g4hwdW93fGoTn7LgrmQ5ZdqeG0AbiIa9tqo2kkr2L28=; b=ywduekpZNitFFHDaSdnD6rtHppOJeLe1jKlXzU5OQzBFyPPt65vOeO6t jJu+RAiUqw0uHXFErlC64RzgOo/SxaRMcinlqmR0sKSXs2dtq7uAG4pYK TqmZuThZfD7gyO+0173CtUVWESk1ZaaQmSmvkl0LY17Ef0LC3mRrBGlRQ 0=; Received: from unknown (HELO ironmsg-SD-alpha.qualcomm.com) ([10.53.140.30]) by alexa-out-sd-01.qualcomm.com with ESMTP; 16 Jun 2022 06:13:32 -0700 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg-SD-alpha.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2022 06:13:32 -0700 Received: from [10.216.41.43] (10.80.80.8) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Thu, 16 Jun 2022 06:13:29 -0700 Message-ID: Date: Thu, 16 Jun 2022 18:43:24 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH] cgroup.c: add helper __cset_cgroup_from_root to cleanup duplicated codes Content-Language: en-US To: Lin Feng , , , CC: , References: <20220616103830.197458-1-linf@wangsu.com> From: Mukesh Ojha In-Reply-To: <20220616103830.197458-1-linf@wangsu.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.47.97.222) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 6/16/2022 4:08 PM, Lin Feng wrote: > No funtionality change, but save us some lines. > > Signed-off-by: Lin Feng > --- > 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 -Mukesh