diff mbox series

[04/91] proc: save LOC in __xlate_proc_name()

Message ID 20210507010213.V8MhqooKS%akpm@linux-foundation.org (mailing list archive)
State New
Headers show
Series [01/91] alpha: eliminate old-style function definitions | expand

Commit Message

Andrew Morton May 7, 2021, 1:02 a.m. UTC
From: Alexey Dobriyan <adobriyan@gmail.com>
Subject: proc: save LOC in __xlate_proc_name()

Can't look at this verbosity anymore.

Link: https://lkml.kernel.org/r/YFYXAp/fgq405qcy@localhost.localdomain
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

 fs/proc/generic.c |   11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)


Linus Torvalds May 7, 2021, 2:24 a.m. UTC | #1
On Thu, May 6, 2021 at 6:02 PM Andrew Morton <akpm@linux-foundation.org> wrote:
> From: Alexey Dobriyan <adobriyan@gmail.com>
> Subject: proc: save LOC in __xlate_proc_name()
> +       while ((next = strchr(cp, '/'))) {

Please don't do this.

Yes, gcc suggests that double parentheses syntax around an assignment
to avoid warnings.

gcc is wrong, and is being completely stupid.

The proper way to avoid the "assignment in conditional" warning is to
(surprise, surprise) USE A CONDITIONAL.

So that

          while ((next = strchr(cp, '/'))) {

is the crazy rantings of a misguided compiler. No sane human should
ever care about some odd double parenthesis syntax. We're not writing
LISP, for chrissake.

The proper way to write this is

          while ((next = strchr(cp, '/')) != NULL) {

which makes sense to not just a machine, but to a human, and avoids
the whole "assignment used as a conditional" warning very naturally.

See? Now it uses a conditional as a conditional. Doesn't that make a
whole lot more sense than the crazy ramblings of a broken machine

I fixed it up manually, I just wanted to rant against this kind of
"mindlessly take advice from the compiler without thinking about it".

diff mbox series


--- a/fs/proc/generic.c~proc-save-loc-in-__xlate_proc_name
+++ a/fs/proc/generic.c
@@ -166,15 +166,8 @@  static int __xlate_proc_name(const char
 	const char     		*cp = name, *next;
 	struct proc_dir_entry	*de;
-	de = *ret;
-	if (!de)
-		de = &proc_root;
-	while (1) {
-		next = strchr(cp, '/');
-		if (!next)
-			break;
+	de = *ret ?: &proc_root;
+	while ((next = strchr(cp, '/'))) {
 		de = pde_subdir_find(de, cp, next - cp);
 		if (!de) {
 			WARN(1, "name '%s'\n", name);