Skip to contentSkip to conversation

sysctl: use min() helper for namecmp()

PATCH In review Masahiro Yamada 2 participants 5 messages Jan 4, 2021 – Apr 11, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sysctl: use min() helper for namecmp()

Make it slightly readable by using min().

---

 fs/proc/proc_sysctl.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
fs/proc/proc_sysctl.c +1 -6
index 317899222d7f..86341c0f0c40 100644
@@ -94,14 +94,9 @@ static void sysctl_print_dir(struct ctl_dir *dir)
 
 static int namecmp(const char *name1, int len1, const char *name2, int len2)
 {
-	int minlen;
 	int cmp;
 
-	minlen = len1;
-	if (minlen > len2)
-		minlen = len2;
-
-	cmp = memcmp(name1, name2, minlen);
+	cmp = memcmp(name1, name2, min(len1, len2));
 	if (cmp == 0)
 		cmp = len1 - len2;
 	return cmp;
Signature · 1 line
2.27.0
#2 lore raw
In reply to Masahiro Yamada

(CC: Andrew Morton)

A friendly reminder.

This is just a minor clean-up.

If nobody picks it up,
I hope perhaps Andrew Morton will do.

This patch:
https://lore.kernel.org/patchwork/patch/1360092/

Quoted 32 lines · Masahiro Yamada

Make it slightly readable by using min().

---

 fs/proc/proc_sysctl.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
fs/proc/proc_sysctl.c +1 -7
index 317899222d7f..86341c0f0c40 100644
@@ -94,14 +94,9 @@ static void sysctl_print_dir(struct ctl_dir *dir)
 
 static int namecmp(const char *name1, int len1, const char *name2, int len2)
 {
-       int minlen;
        int cmp;
 
-       minlen = len1;
-       if (minlen > len2)
-               minlen = len2;
-
-       cmp = memcmp(name1, name2, minlen);
+       cmp = memcmp(name1, name2, min(len1, len2));
        if (cmp == 0)
                cmp = len1 - len2;
        return cmp;
--

2.27.0

Signature · 2 lines
Best Regards
Masahiro Yamada
Acked-by
#3 lore raw
Quoted 10 lines · Masahiro Yamada

(CC: Andrew Morton)

A friendly reminder.

This is just a minor clean-up.

If nobody picks it up,
I hope perhaps Andrew Morton will do.

Quoted 12 lines

This patch:
https://lore.kernel.org/patchwork/patch/1360092/

Quoted 4 lines · Masahiro Yamada

Make it slightly readable by using min().

Feel free to take this via your tree Masahiro. Thanks!

-Kees

Quoted 33 lines
Quoted 28 lines

---

 fs/proc/proc_sysctl.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
fs/proc/proc_sysctl.c +1 -7
index 317899222d7f..86341c0f0c40 100644
@@ -94,14 +94,9 @@ static void sysctl_print_dir(struct ctl_dir *dir)
 
 static int namecmp(const char *name1, int len1, const char *name2, int len2)
 {
-       int minlen;
        int cmp;
 
-       minlen = len1;
-       if (minlen > len2)
-               minlen = len2;
-
-       cmp = memcmp(name1, name2, minlen);
+       cmp = memcmp(name1, name2, min(len1, len2));
        if (cmp == 0)
                cmp = len1 - len2;
        return cmp;
--

2.27.0

Signature · 2 lines
Best Regards
Masahiro Yamada
Signature · 6 lines
Kees Cook

Reviewed-by: Kees Cook <[email protected]>

-- 
Kees Cook
#4 lore raw
Quoted 65 lines · Kees Cook
Quoted 10 lines · Masahiro Yamada

(CC: Andrew Morton)

A friendly reminder.

This is just a minor clean-up.

If nobody picks it up,
I hope perhaps Andrew Morton will do.

Quoted 12 lines

This patch:
https://lore.kernel.org/patchwork/patch/1360092/

Quoted 4 lines · Masahiro Yamada

Make it slightly readable by using min().

Feel free to take this via your tree Masahiro. Thanks!

-Kees

Quoted 25 lines
Quoted 25 lines

---

 fs/proc/proc_sysctl.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
fs/proc/proc_sysctl.c +1 -6
index 317899222d7f..86341c0f0c40 100644
@@ -94,14 +94,9 @@ static void sysctl_print_dir(struct ctl_dir *dir)
 
 static int namecmp(const char *name1, int len1, const char *name2, int len2)
 {
-       int minlen;
        int cmp;
 
-       minlen = len1;
-       if (minlen > len2)
-               minlen = len2;
-
-       cmp = memcmp(name1, name2, minlen);
+       cmp = memcmp(name1, name2, min(len1, len2));
        if (cmp == 0)
                cmp = len1 - len2;
        return cmp;
Quoted 8 lines
Quoted 3 lines

--
2.27.0

--
Best Regards
Masahiro Yamada

Quoted 7 lines

--
Kees Cook

--
Kees Cook

Applied to linux-kbuild.

Signature · 2 lines
Best Regards
Masahiro Yamada