RE: [PATCH 06/14] d_path: don't bother with return value of prepend()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




> -----Original Message-----
> From: Al Viro <viro@xxxxxxxxxxxxxxxx> On Behalf Of Al Viro
> Sent: Wednesday, May 19, 2021 8:49 AM
> To: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
> Cc: Justin He <Justin.He@xxxxxxx>; Petr Mladek <pmladek@xxxxxxxx>; Steven
> Rostedt <rostedt@xxxxxxxxxxx>; Sergey Senozhatsky
> <senozhatsky@xxxxxxxxxxxx>; Andy Shevchenko
> <andriy.shevchenko@xxxxxxxxxxxxxxx>; Rasmus Villemoes
> <linux@xxxxxxxxxxxxxxxxxx>; Jonathan Corbet <corbet@xxxxxxx>; Heiko
> Carstens <hca@xxxxxxxxxxxxx>; Vasily Gorbik <gor@xxxxxxxxxxxxx>; Christian
> Borntraeger <borntraeger@xxxxxxxxxx>; Eric W . Biederman
> <ebiederm@xxxxxxxxxxxx>; Darrick J. Wong <darrick.wong@xxxxxxxxxx>; Peter
> Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>; Ira Weiny <ira.weiny@xxxxxxxxx>;
> Eric Biggers <ebiggers@xxxxxxxxxx>; Ahmed S. Darwish
> <a.darwish@xxxxxxxxxxxxx>; open list:DOCUMENTATION <linux-
> doc@xxxxxxxxxxxxxxx>; Linux Kernel Mailing List <linux-
> kernel@xxxxxxxxxxxxxxx>; linux-s390 <linux-s390@xxxxxxxxxxxxxxx>; linux-
> fsdevel <linux-fsdevel@xxxxxxxxxxxxxxx>
> Subject: [PATCH 06/14] d_path: don't bother with return value of prepend()
>
> Only simple_dname() checks it, and there we can simply do those
> calls and check for overflow (by looking of negative buflen)
> in the end.
>
> Signed-off-by: Al Viro <viro@xxxxxxxxxxxxxxxxxx>

Reviewed-by: Jia He <justin.he@xxxxxxx>

--
Cheers,
Justin (Jia He)
> ---
>  fs/d_path.c | 20 +++++++++-----------
>  1 file changed, 9 insertions(+), 11 deletions(-)
>
> diff --git a/fs/d_path.c b/fs/d_path.c
> index 311d43287572..72b8087aaf9c 100644
> --- a/fs/d_path.c
> +++ b/fs/d_path.c
> @@ -8,14 +8,13 @@
>  #include <linux/prefetch.h>
>  #include "mount.h"
>
> -static int prepend(char **buffer, int *buflen, const char *str, int
> namelen)
> +static void prepend(char **buffer, int *buflen, const char *str, int
> namelen)
>  {
>       *buflen -= namelen;
> -     if (*buflen < 0)
> -             return -ENAMETOOLONG;
> -     *buffer -= namelen;
> -     memcpy(*buffer, str, namelen);
> -     return 0;
> +     if (likely(*buflen >= 0)) {
> +             *buffer -= namelen;
> +             memcpy(*buffer, str, namelen);
> +     }
>  }
>
>  /**
> @@ -298,11 +297,10 @@ char *simple_dname(struct dentry *dentry, char
> *buffer, int buflen)
>  {
>       char *end = buffer + buflen;
>       /* these dentries are never renamed, so d_lock is not needed */
> -     if (prepend(&end, &buflen, " (deleted)", 11) ||
> -         prepend(&end, &buflen, dentry->d_name.name, dentry->d_name.len)
> ||
> -         prepend(&end, &buflen, "/", 1))
> -             end = ERR_PTR(-ENAMETOOLONG);
> -     return end;
> +     prepend(&end, &buflen, " (deleted)", 11);
> +     prepend(&end, &buflen, dentry->d_name.name, dentry->d_name.len);
> +     prepend(&end, &buflen, "/", 1);
> +     return buflen >= 0 ? end : ERR_PTR(-ENAMETOOLONG);
>  }
>
>  /*
> --
> 2.11.0

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.




[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux