From: Samyak <samyak.bambole07@gmail.com>
To: akpm@linux-foundation.org, kees@kernel.org
Cc: andy@kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org,
Samyak <samyak.bambole07@gmail.com>
Subject: [PATCH] [RFC PATCH] lib/string: fix coding style issues
Date: Sat, 14 Feb 2026 19:21:07 +0530 [thread overview]
Message-ID: <20260214135107.595089-1-samyak.bambole07@gmail.com> (raw)
- 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@gmail.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
next reply other threads:[~2026-02-14 13:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-14 13:51 Samyak [this message]
2026-02-14 14:02 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260214135107.595089-1-samyak.bambole07@gmail.com \
--to=samyak.bambole07@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andy@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®