* [PATCH] [RFC PATCH] lib/string: fix coding style issues
@ 2026-02-14 13:51 Samyak
2026-02-14 14:02 ` Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: Samyak @ 2026-02-14 13:51 UTC (permalink / raw)
To: akpm, kees; +Cc: andy, linux-kernel, linux-hardening, Samyak
- 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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] [RFC PATCH] lib/string: fix coding style issues
2026-02-14 13:51 [PATCH] [RFC PATCH] lib/string: fix coding style issues Samyak
@ 2026-02-14 14:02 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2026-02-14 14:02 UTC (permalink / raw)
To: Samyak; +Cc: akpm, kees, andy, linux-kernel, linux-hardening
On Sat, Feb 14, 2026 at 07:21:07PM +0530, Samyak wrote:
> - 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 ++++++++++++++++-----------
If you want to get involved in kernel work, please do coding style
changes in drivers/staging/ which is there to learn on how to do this.
Only after doing this a lot, and getting experience, should you venture
out of drivers/staging/
Also, many subsystems do not want coding style fixes for obvious reasons
(i.e. they change over time and keeping the whole codebase up to date
like this would be constant churn.)
Hint, this patch would need to be broken up anyway, you should only do
"one logical thing" per patch. And "fix all coding style issues" is not
one thing :)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-02-14 14:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-14 13:51 [PATCH] [RFC PATCH] lib/string: fix coding style issues Samyak
2026-02-14 14:02 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox