Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1310079
| From | Geert Uytterhoeven <geert@linux-m68k.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 2/8] kernfs: implement kernfs_walk_and_get() |
| Date | 2016-01-15 13:30 +0100 |
| Message-ID | <qRbFV-60h-21@gated-at.bofh.it> (permalink) |
| References | <qDcBQ-2jb-5@gated-at.bofh.it> <qDcBQ-2jb-7@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Mon, Dec 7, 2015 at 11:38 PM, Tejun Heo <tj@kernel.org> wrote:
> Implement kernfs_walk_and_get() which is similar to
> kernfs_find_and_get() but can walk a path instead of just a name.
>
> v2: Use strlcpy() instead of strlen() + memcpy() as suggested by
> David.
>
> Signed-off-by: Tejun Heo <tj@kernel.org>
> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: David Miller <davem@davemloft.net>
> ---
> fs/kernfs/dir.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
> include/linux/kernfs.h | 12 ++++++++++++
> 2 files changed, 58 insertions(+)
>
> diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
> index 91e0045..742bf4a 100644
> --- a/fs/kernfs/dir.c
> +++ b/fs/kernfs/dir.c
> @@ -694,6 +694,29 @@ static struct kernfs_node *kernfs_find_ns(struct kernfs_node *parent,
> return NULL;
> }
>
> +static struct kernfs_node *kernfs_walk_ns(struct kernfs_node *parent,
> + const unsigned char *path,
> + const void *ns)
> +{
> + static char path_buf[PATH_MAX]; /* protected by kernfs_mutex */
This is showing up in bloat-o-meter as increasing kernel size by 4 KiB.
> + size_t len = strlcpy(path_buf, path, PATH_MAX);
The full input string is copied because strsep() replaces the delimiters by
zeroes?
Can this be handled in some other way?
> + char *p = path_buf;
> + char *name;
> +
> + lockdep_assert_held(&kernfs_mutex);
> +
> + if (len >= PATH_MAX)
> + return NULL;
> +
> + while ((name = strsep(&p, "/")) && parent) {
> + if (*name == '\0')
> + continue;
> + parent = kernfs_find_ns(parent, name, ns);
> + }
> +
> + return parent;
> +}
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread
Re: [PATCH 2/8] kernfs: implement kernfs_walk_and_get() Geert Uytterhoeven <geert@linux-m68k.org> - 2016-01-15 13:30 +0100
[PATCH] kernfs: make kernfs_walk_ns() use kernfs_pr_cont_buf[] Tejun Heo <tj@kernel.org> - 2016-01-15 18:40 +0100
Re: [PATCH] kernfs: make kernfs_walk_ns() use kernfs_pr_cont_buf[] Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-01-15 23:10 +0100
csiph-web