lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260214135107.595089-1-samyak.bambole07@gmail.com>
Date: Sat, 14 Feb 2026 19:21:07 +0530
From: Samyak <samyak.bambole07@...il.com>
To: akpm@...ux-foundation.org,
	kees@...nel.org
Cc: andy@...nel.org,
	linux-kernel@...r.kernel.org,
	linux-hardening@...r.kernel.org,
	Samyak <samyak.bambole07@...il.com>
Subject: [PATCH] [RFC PATCH] lib/string: fix coding style issues

- Add spaces around binary operators
- remove spaces after casts
- Add blank line after variable declarations
- Fix constant on left side of a conditional expression (0 < count ->
  count > 0)
- Remove un-needed braces around single statements

Signed-off-by: Samyak Bambole <samyak.bambole07@...il.com>
---
This is my first linux kernel patch. I have compiled and tested the
changes on QEMU. I would appreciate any feedback. Thanks.

 lib/string.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/lib/string.c b/lib/string.c
index b632c71df..8f5582d9a 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -127,12 +127,13 @@ ssize_t sized_strscpy(char *dest, const char *src, size_t count)
 	 */
 	if ((long)src & (sizeof(long) - 1)) {
 		size_t limit = PAGE_SIZE - ((long)src & (PAGE_SIZE - 1));
+
 		if (limit < max)
 			max = limit;
 	}
 #else
 	/* If src or dest is unaligned, don't do word-at-a-time. */
-	if (((long) dest | (long) src) & (sizeof(long) - 1))
+	if (((long)dest | (long)src) & (sizeof(long) - 1))
 		max = 0;
 #endif
 #endif
@@ -150,23 +151,24 @@ ssize_t sized_strscpy(char *dest, const char *src, size_t count)
 		unsigned long c, data;
 
 #ifdef CONFIG_DCACHE_WORD_ACCESS
-		c = load_unaligned_zeropad(src+res);
+		c = load_unaligned_zeropad(src + res);
 #else
-		c = read_word_at_a_time(src+res);
+		c = read_word_at_a_time(src + res);
 #endif
 		if (has_zero(c, &data, &constants)) {
 			data = prep_zero_mask(c, data, &constants);
 			data = create_zero_mask(data);
-			*(unsigned long *)(dest+res) = c & zero_bytemask(data);
+			*(unsigned long *)(dest + res) = c &
+							 zero_bytemask(data);
 			return res + find_zero(data);
 		}
 		count -= sizeof(unsigned long);
 		if (unlikely(!count)) {
 			c &= ALLBUTLAST_BYTE_MASK;
-			*(unsigned long *)(dest+res) = c;
+			*(unsigned long *)(dest + res) = c;
 			return -E2BIG;
 		}
-		*(unsigned long *)(dest+res) = c;
+		*(unsigned long *)(dest + res) = c;
 		res += sizeof(unsigned long);
 		max -= sizeof(unsigned long);
 	}
@@ -261,7 +263,7 @@ size_t strlcat(char *dest, const char *src, size_t count)
 	dest += dsize;
 	count -= dsize;
 	if (len >= count)
-		len = count-1;
+		len = count - 1;
 	__builtin_memcpy(dest, src, len);
 	dest[len] = 0;
 	return res;
@@ -380,6 +382,7 @@ char *strnchrnul(const char *s, size_t count, int c)
 char *strrchr(const char *s, int c)
 {
 	const char *last = NULL;
+
 	do {
 		if (*s == (char)c)
 			last = s;
@@ -679,6 +682,7 @@ __visible int memcmp(const void *cs, const void *ct, size_t count)
 	if (count >= sizeof(unsigned long)) {
 		const unsigned long *u1 = cs;
 		const unsigned long *u2 = ct;
+
 		do {
 			if (get_unaligned(u1) != get_unaligned(u2))
 				break;
@@ -690,9 +694,10 @@ __visible int memcmp(const void *cs, const void *ct, size_t count)
 		ct = u2;
 	}
 #endif
-	for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
+	for (su1 = cs, su2 = ct; count > 0; ++su1, ++su2, count--) {
 		if ((res = *su1 - *su2) != 0)
 			break;
+	}
 	return res;
 }
 EXPORT_SYMBOL(memcmp);
@@ -737,7 +742,7 @@ void *memscan(void *addr, int c, size_t size)
 		p++;
 		size--;
 	}
-  	return (void *)p;
+	return (void *)p;
 }
 EXPORT_SYMBOL(memscan);
 #endif
@@ -805,10 +810,10 @@ EXPORT_SYMBOL(strnstr);
 void *memchr(const void *s, int c, size_t n)
 {
 	const unsigned char *p = s;
+
 	while (n-- != 0) {
-        	if ((unsigned char)c == *p++) {
+		if ((unsigned char)c == *p++)
 			return (void *)(p - 1);
-		}
 	}
 	return NULL;
 }
-- 
2.53.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ