mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: John Johansen <john.johansen@canonical.com>
To: Luis Chamberlain <mcgrof@kernel.org>,
	ebiederm@xmission.com, keescook@chromium.org, yzaikin@google.com,
	paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com,
	luto@amacapital.net, wad@chromium.org, dverkamp@chromium.org,
	paulmck@kernel.org, baihaowen@meizu.com, frederic@kernel.org,
	jeffxu@google.com, ebiggers@kernel.org, tytso@mit.edu,
	guoren@kernel.org
Cc: j.granados@samsung.com, zhangpeng362@huawei.com,
	tangmeng@uniontech.com, willy@infradead.org,
	nixiaoming@huawei.com, sujiaxun@uniontech.com,
	patches@lists.linux.dev, linux-fsdevel@vger.kernel.org,
	apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org,
	linux-csky@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 02/11] proc_sysctl: move helper which creates required subdirectories
Date: Thu, 2 Mar 2023 14:56:21 -0800	[thread overview]
Message-ID: <e97bf2c2-6879-de79-1e07-276bc2192d6e@canonical.com> (raw)
In-Reply-To: <20230302202826.776286-3-mcgrof@kernel.org>

On 3/2/23 12:28, Luis Chamberlain wrote:
> Move the code which creates the subdirectories for a ctl table
> into a helper routine so to make it easier to review. Document
> the goal.
> 
> This creates no functional changes.
> 
> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>

Reviewed-by: John Johansen <john.johansen@canonical.com>

> ---
>   fs/proc/proc_sysctl.c | 56 ++++++++++++++++++++++++-------------------
>   1 file changed, 32 insertions(+), 24 deletions(-)
> 
> diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
> index 1df0beb50dbe..6b9b2694d430 100644
> --- a/fs/proc/proc_sysctl.c
> +++ b/fs/proc/proc_sysctl.c
> @@ -1283,6 +1283,35 @@ static int insert_links(struct ctl_table_header *head)
>   	return err;
>   }
>   
> +/* Find the directory for the ctl_table. If one is not found create it. */
> +static struct ctl_dir *sysctl_mkdir_p(struct ctl_dir *dir, const char *path)
> +{
> +	const char *name, *nextname;
> +
> +	for (name = path; name; name = nextname) {
> +		int namelen;
> +		nextname = strchr(name, '/');
> +		if (nextname) {
> +			namelen = nextname - name;
> +			nextname++;
> +		} else {
> +			namelen = strlen(name);
> +		}
> +		if (namelen == 0)
> +			continue;
> +
> +		/*
> +		 * namelen ensures if name is "foo/bar/yay" only foo is
> +		 * registered first. We traverse as if using mkdir -p and
> +		 * return a ctl_dir for the last directory entry.
> +		 */
> +		dir = get_subdir(dir, name, namelen);
> +		if (IS_ERR(dir))
> +			break;
> +	}
> +	return dir;
> +}
> +
>   /**
>    * __register_sysctl_table - register a leaf sysctl table
>    * @set: Sysctl tree to register on
> @@ -1334,7 +1363,6 @@ struct ctl_table_header *__register_sysctl_table(
>   {
>   	struct ctl_table_root *root = set->dir.header.root;
>   	struct ctl_table_header *header;
> -	const char *name, *nextname;
>   	struct ctl_dir *dir;
>   	struct ctl_table *entry;
>   	struct ctl_node *node;
> @@ -1359,29 +1387,9 @@ struct ctl_table_header *__register_sysctl_table(
>   	dir->header.nreg++;
>   	spin_unlock(&sysctl_lock);
>   
> -	/* Find the directory for the ctl_table */
> -	for (name = path; name; name = nextname) {
> -		int namelen;
> -		nextname = strchr(name, '/');
> -		if (nextname) {
> -			namelen = nextname - name;
> -			nextname++;
> -		} else {
> -			namelen = strlen(name);
> -		}
> -		if (namelen == 0)
> -			continue;
> -
> -		/*
> -		 * namelen ensures if name is "foo/bar/yay" only foo is
> -		 * registered first. We traverse as if using mkdir -p and
> -		 * return a ctl_dir for the last directory entry.
> -		 */
> -		dir = get_subdir(dir, name, namelen);
> -		if (IS_ERR(dir))
> -			goto fail;
> -	}
> -
> +	dir = sysctl_mkdir_p(dir, path);
> +	if (IS_ERR(dir))
> +		goto fail;
>   	spin_lock(&sysctl_lock);
>   	if (insert_header(dir, header))
>   		goto fail_put_dir_locked;


  reply	other threads:[~2023-03-02 22:56 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-02 20:28 [PATCH 00/11] sysctl: deprecate register_sysctl_paths() Luis Chamberlain
2023-03-02 20:28 ` [PATCH 01/11] proc_sysctl: update docs for __register_sysctl_table() Luis Chamberlain
2023-03-02 20:28 ` [PATCH 02/11] proc_sysctl: move helper which creates required subdirectories Luis Chamberlain
2023-03-02 22:56   ` John Johansen [this message]
2023-03-02 20:28 ` [PATCH 03/11] sysctl: clarify register_sysctl_init() base directory order Luis Chamberlain
2023-03-02 20:28 ` [PATCH 04/11] apparmor: simplify sysctls with register_sysctl_init() Luis Chamberlain
2023-03-02 20:42   ` Georgia Garcia
2023-03-02 22:51   ` John Johansen
2023-03-02 20:28 ` [PATCH 05/11] loadpin: simplify sysctls use with register_sysctl() Luis Chamberlain
2023-03-02 22:56   ` Kees Cook
2023-03-02 22:58   ` John Johansen
2023-03-02 20:28 ` [PATCH 06/11] yama: simplfy sysctls " Luis Chamberlain
2023-03-02 22:56   ` Kees Cook
2023-03-02 20:28 ` [PATCH 07/11] seccomp: simplify sysctls with register_sysctl_init() Luis Chamberlain
2023-03-02 22:56   ` Kees Cook
2023-03-02 20:28 ` [PATCH 08/11] kernel: pid_namespace: simplify sysctls with register_sysctl() Luis Chamberlain
2023-03-02 23:13   ` Jeff Xu
2023-03-09 22:11     ` Luis Chamberlain
2023-03-09 22:27       ` Andrew Morton
2023-03-19 20:47         ` Luis Chamberlain
2023-03-10  4:14       ` Eric Biggers
2023-03-10  7:00         ` Luis Chamberlain
2023-03-02 20:28 ` [PATCH 09/11] fs-verity: " Luis Chamberlain
2023-03-07 19:47   ` Eric Biggers
2023-03-02 20:28 ` [PATCH 10/11] csky: simplify alignment sysctl registration Luis Chamberlain
2023-03-02 20:28 ` [PATCH 11/11] proc_sysctl: deprecate register_sysctl_paths() Luis Chamberlain
2023-03-10  4:17   ` Eric Biggers
2023-03-10  7:01     ` Luis Chamberlain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e97bf2c2-6879-de79-1e07-276bc2192d6e@canonical.com \
    --to=john.johansen@canonical.com \
    --cc=apparmor@lists.ubuntu.com \
    --cc=baihaowen@meizu.com \
    --cc=dverkamp@chromium.org \
    --cc=ebiederm@xmission.com \
    --cc=ebiggers@kernel.org \
    --cc=frederic@kernel.org \
    --cc=guoren@kernel.org \
    --cc=j.granados@samsung.com \
    --cc=jeffxu@google.com \
    --cc=jmorris@namei.org \
    --cc=keescook@chromium.org \
    --cc=linux-csky@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mcgrof@kernel.org \
    --cc=nixiaoming@huawei.com \
    --cc=patches@lists.linux.dev \
    --cc=paul@paul-moore.com \
    --cc=paulmck@kernel.org \
    --cc=serge@hallyn.com \
    --cc=sujiaxun@uniontech.com \
    --cc=tangmeng@uniontech.com \
    --cc=tytso@mit.edu \
    --cc=wad@chromium.org \
    --cc=willy@infradead.org \
    --cc=yzaikin@google.com \
    --cc=zhangpeng362@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®