[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250106102647.GB20870@noisy.programming.kicks-ass.net>
Date: Mon, 6 Jan 2025 11:26:47 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: Oleg Nesterov <oleg@...hat.com>
Cc: "Masami Hiramatsu (Google)" <mhiramat@...nel.org>,
Steven Rostedt <rostedt@...dmis.org>,
Anil S Keshavamurthy <anil.s.keshavamurthy@...el.com>,
"David S . Miller" <davem@...emloft.net>,
Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
Tzvetomir Stoyanov <tz.stoyanov@...il.com>,
Naveen N Rao <naveen@...nel.org>,
Josh Poimboeuf <jpoimboe@...nel.org>,
Jason Baron <jbaron@...mai.com>, Ard Biesheuvel <ardb@...nel.org>,
linux-kernel@...r.kernel.org, linux-trace-kernel@...r.kernel.org
Subject: Re: DEFINE_FREE/CLASS && code readability (Was: [PATCH v2 2/6]
Provide __free(argv) for argv_split() users)
On Sun, Jan 05, 2025 at 03:14:22PM +0100, Oleg Nesterov wrote:
> OK, so it can be used as
>
> void func(void)
> {
> char **argv __free(argv) = argv_split(...);
> do_something(argv);
> return;
> }
>
> And I cry every time when I read the code like this ;)
>
> Because, to understand this code, I need to do the "nontrivial" grep to find
> "DEFINE_FREE(argv,".
>
> Perhaps we can establish a simple rule that every DEFINE_FREE() or DEFINE_CLASS()
> should add another #define? I mean something like
>
>
> DEFINE_FREE(argv, char **, if (!IS_ERR_OR_NULL(_T)) argv_free(_T))
> #define __FREE_ARGV __free(argv)
>
> void func(void)
> {
> char **argv __FREE_ARGV = argv_split(...);
> do_something(argv);
> return;
> }
>
> This way I can press Ctrl-] and see what the cleanup code actually does.
> Can save a second or two. Important when you try to read the code you are
> not familiar with.
Right, so I've been playing with neovim and clangd (lsp), and I'm very
disappointed to have to tell you that that also doesn't get it :-(
One thing we can and should do is something like:
diff --git a/scripts/tags.sh b/scripts/tags.sh
index b21236377998..f01d694abe65 100755
--- a/scripts/tags.sh
+++ b/scripts/tags.sh
@@ -212,6 +212,8 @@ regex_c=(
'/^SEQCOUNT_LOCKTYPE(\([^,]*\),[[:space:]]*\([^,]*\),[^)]*)/seqcount_\2_init/'
'/^\<DECLARE_IDTENTRY[[:alnum:]_]*([^,)]*,[[:space:]]*\([[:alnum:]_]\+\)/\1/'
'/^\<DEFINE_IDTENTRY[[:alnum:]_]*([[:space:]]*\([[:alnum:]_]\+\)/\1/'
+ '/^\<DEFINE_FREE(\([[:alnum:]_]\+\)/cleanup_\1/'
+ '/^\<DEFINE_CLASS(\([[:alnum:]_]\+\)/class_\1/'
)
regex_kconfig=(
'/^[[:blank:]]*\(menu\|\)config[[:blank:]]\+\([[:alnum:]_]\+\)/\2/'
That should be able to let you do: ':ts cleanup_argv'
Powered by blists - more mailing lists