lkml.org 
[lkml]   [2021]   [May]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    SubjectRE: [PATCH 08/14] d_path: make prepend_name() boolean
    Date
    Hi Al

    > -----Original Message-----
    > From: Al Viro <viro@ftp.linux.org.uk> On Behalf Of Al Viro
    > Sent: Wednesday, May 19, 2021 8:49 AM
    > To: Linus Torvalds <torvalds@linux-foundation.org>
    > Cc: Justin He <Justin.He@arm.com>; Petr Mladek <pmladek@suse.com>; Steven
    > Rostedt <rostedt@goodmis.org>; Sergey Senozhatsky
    > <senozhatsky@chromium.org>; Andy Shevchenko
    > <andriy.shevchenko@linux.intel.com>; Rasmus Villemoes
    > <linux@rasmusvillemoes.dk>; Jonathan Corbet <corbet@lwn.net>; Heiko
    > Carstens <hca@linux.ibm.com>; Vasily Gorbik <gor@linux.ibm.com>; Christian
    > Borntraeger <borntraeger@de.ibm.com>; Eric W . Biederman
    > <ebiederm@xmission.com>; Darrick J. Wong <darrick.wong@oracle.com>; Peter
    > Zijlstra (Intel) <peterz@infradead.org>; Ira Weiny <ira.weiny@intel.com>;
    > Eric Biggers <ebiggers@google.com>; Ahmed S. Darwish
    > <a.darwish@linutronix.de>; open list:DOCUMENTATION <linux-
    > doc@vger.kernel.org>; Linux Kernel Mailing List <linux-
    > kernel@vger.kernel.org>; linux-s390 <linux-s390@vger.kernel.org>; linux-
    > fsdevel <linux-fsdevel@vger.kernel.org>
    > Subject: [PATCH 08/14] d_path: make prepend_name() boolean
    >
    > It returns only 0 or -ENAMETOOLONG and both callers only check if
    > the result is negative. Might as well return true on success and
    > false on failure...
    >
    > Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
    > ---
    > fs/d_path.c | 12 ++++++------
    > 1 file changed, 6 insertions(+), 6 deletions(-)
    >
    > diff --git a/fs/d_path.c b/fs/d_path.c
    > index 327cc3744554..83db83446afd 100644
    > --- a/fs/d_path.c
    > +++ b/fs/d_path.c
    > @@ -34,15 +34,15 @@ static void prepend(char **buffer, int *buflen, const
    > char *str, int namelen)
    > *
    > * Load acquire is needed to make sure that we see that terminating NUL.
    > */
    > -static int prepend_name(char **buffer, int *buflen, const struct qstr
    > *name)
    > +static bool prepend_name(char **buffer, int *buflen, const struct qstr
    > *name)
    > {
    > const char *dname = smp_load_acquire(&name->name); /* ^^^ */
    > u32 dlen = READ_ONCE(name->len);
    > char *p;
    >
    > *buflen -= dlen + 1;
    > - if (*buflen < 0)
    > - return -ENAMETOOLONG;
    > + if (unlikely(*buflen < 0))
    > + return false;

    I don't object to this patch itself.
    Just wonder whether we need to relax the check condition of "*buflen < 0" ?

    Given that in vsnprintf code path, sometimes the *buflen is < 0.

    Please see https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/lib/vsprintf.c#n2698

    --
    Cheers,

    Justin (Jia He)
    > p = *buffer -= dlen + 1;
    > *p++ = '/';
    > while (dlen--) {
    > @@ -51,7 +51,7 @@ static int prepend_name(char **buffer, int *buflen, const
    > struct qstr *name)
    > break;
    > *p++ = c;
    > }
    > - return 0;
    > + return true;
    > }
    >
    > /**
    > @@ -127,7 +127,7 @@ static int prepend_path(const struct path *path,
    > }
    > parent = dentry->d_parent;
    > prefetch(parent);
    > - if (unlikely(prepend_name(&bptr, &blen, &dentry->d_name) < 0))
    > + if (!prepend_name(&bptr, &blen, &dentry->d_name))
    > break;
    >
    > dentry = parent;
    > @@ -305,7 +305,7 @@ static char *__dentry_path(const struct dentry *d, char
    > *p, int buflen)
    > const struct dentry *parent = dentry->d_parent;
    >
    > prefetch(parent);
    > - if (unlikely(prepend_name(&end, &len, &dentry->d_name) < 0))
    > + if (!prepend_name(&end, &len, &dentry->d_name))
    > break;
    >
    > dentry = parent;
    > --
    > 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.

    \
     
     \ /
      Last update: 2021-05-20 11:13    [W:7.318 / U:0.008 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site