diff mbox series

[v2] ext4: Simplify code in ext4_decode_error()

Message ID 4c299692e35a0a14add58a5dd399d07843a4d350.1694934182.git.christophe.jaillet@wanadoo.fr
State New
Headers show
Series [v2] ext4: Simplify code in ext4_decode_error() | expand

Commit Message

Christophe JAILLET Sept. 17, 2023, 7:03 a.m. UTC
snprintf() returns the number of characters which would be generated,
excluding the trailing NULL. Here the value is always >= 7, so the test
is always true.

Instead of fixing the test, just remove it. What matters is that the
string is NULL terminated.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
v2:
   - remove the bogus check, instead of fixing it
   - Remove the Fixes tag (was: ac27a0ec112a ("[PATCH] ext4: initial copy of files from ext3"))

v1:
   https://lore.kernel.org/all/2c0edffd8557807c6cd6d55111482c5cad7c8f2f.1694275603.git.christophe.jaillet@wanadoo.fr/

The comment about nbuf being NULL or not, and the related test could be
removed, but keeping it is harmless and more future proof.
---
 fs/ext4/super.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 2684ed69403e..86ed931f402a 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -947,9 +947,8 @@  const char *ext4_decode_error(struct super_block *sb, int errno,
 		 * errors, textualise them now.  Else we just return
 		 * NULL. */
 		if (nbuf) {
-			/* Check for truncated error codes... */
-			if (snprintf(nbuf, 16, "error %d", -errno) >= 0)
-				errstr = nbuf;
+			snprintf(nbuf, 16, "error %d", -errno);
+			errstr = nbuf;
 		}
 		break;
 	}