diff mbox series

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

Message ID 20210519004901.3829541-6-viro@zeniv.linux.org.uk (mailing list archive)
State New, archived
Headers show
Series [01/14] d_path: "\0" is {0,0}, not {0} | expand

Commit Message

Al Viro May 19, 2021, 12:48 a.m. UTC
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@zeniv.linux.org.uk>
---
 fs/d_path.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

Comments

Justin He June 24, 2021, 6:13 a.m. UTC | #1
> -----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 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@zeniv.linux.org.uk>

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

--
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.
diff mbox series

Patch

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);
 }
 
 /*