From: Oleg Nesterov <oleg@redhat.com>
To: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
Steven Rostedt <rostedt@goodmis.org>,
Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>,
"David S . Miller" <davem@davemloft.net>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Tzvetomir Stoyanov <tz.stoyanov@gmail.com>,
Naveen N Rao <naveen@kernel.org>,
Josh Poimboeuf <jpoimboe@kernel.org>,
Jason Baron <jbaron@akamai.com>, Ard Biesheuvel <ardb@kernel.org>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: DEFINE_FREE/CLASS && code readability (Was: [PATCH v2 2/6] Provide __free(argv) for argv_split() users)
Date: Mon, 6 Jan 2025 15:33:51 +0100 [thread overview]
Message-ID: <20250106143350.GC7233@redhat.com> (raw)
In-Reply-To: <20250106211946.2a1b1351421298150ca8c6bb@kernel.org>
On 01/06, Masami Hiramatsu wrote:
>
> On Sun, 5 Jan 2025 15:14:22 +0100
> Oleg Nesterov <oleg@redhat.com> wrote:
>
> > 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.
>
> That sounds lile a problem of your tool. Do you really need to find the
> DEFINE_FREE()
Yes, ":tag __free_argv" wont work. it is defined by DEFINE_FREE(argv) above.
I need to find this DEFINE_FREE(argv) to see what __free_argv() actually does.
> > Same for DEFINE_CLASS. For example,
> >
> > int ksys_fchown(unsigned int fd, uid_t user, gid_t group)
> > {
> > CLASS(fd, f)(fd);
> >
> > if (fd_empty(f))
> > return -EBADF;
> >
> > return vfs_fchown(fd_file(f), user, group);
> > }
> >
> > If you are not familiar with this code, it looks mysterious until you find
> > DEFINE_CLASS(fd, ...) in include/linux/file.h.
>
> DEFINE_CLASS() is somewhat mysterious to me too :) But if I understand
> correctly, it is for intermediate macro for implementing guard().
Well, in this case you just need to find
DEFINE_CLASS(fd, struct fd, fdput(_T), fdget(fd), int fd)
in include/linux/file.h, after that the code is clear.
> BTW, I agree that 'argv' was too simple. Basically the label name of
> DEFINE_FREE() is better to be a function name for free.
> Let me fix that.
Up to you, but __free(argv) looks good to me.
Oleg.
next prev parent reply other threads:[~2025-01-06 14:34 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-05 12:47 [PATCH v2 0/6] tracing/kprobes: Cleanup with guard and __free Masami Hiramatsu (Google)
2025-01-05 12:47 ` [PATCH v2 1/6] tracing/kprobes: Fix to free objects when failed to copy a symbol Masami Hiramatsu (Google)
2025-01-05 12:47 ` [PATCH v2 2/6] Provide __free(argv) for argv_split() users Masami Hiramatsu (Google)
2025-01-05 14:14 ` DEFINE_FREE/CLASS && code readability (Was: [PATCH v2 2/6] Provide __free(argv) for argv_split() users) Oleg Nesterov
2025-01-06 10:26 ` Peter Zijlstra
2025-01-06 11:18 ` Peter Zijlstra
2025-01-06 14:44 ` Oleg Nesterov
2025-01-11 13:21 ` [tip: locking/core] cleanup, tags: Create tags for the cleanup primitives tip-bot2 for Peter Zijlstra
2025-01-14 21:29 ` Oleg Nesterov
2025-01-06 12:19 ` DEFINE_FREE/CLASS && code readability (Was: [PATCH v2 2/6] Provide __free(argv) for argv_split() users) Masami Hiramatsu
2025-01-06 14:33 ` Oleg Nesterov [this message]
2025-01-05 12:48 ` [PATCH v2 3/6] tracing: Use __free() for argv in dynevent Masami Hiramatsu (Google)
2025-01-05 12:48 ` [PATCH v2 4/6] tracing: Use __free() in trace_probe for cleanup Masami Hiramatsu (Google)
2025-01-05 12:48 ` [PATCH v2 5/6] tracing: Use __free() for kprobe events to cleanup Masami Hiramatsu (Google)
2025-01-06 10:09 ` Masami Hiramatsu
2025-01-05 12:48 ` [PATCH v2 6/6] tracing/kprobes: Simplify __trace_kprobe_create() by removing gotos Masami Hiramatsu (Google)
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=20250106143350.GC7233@redhat.com \
--to=oleg@redhat.com \
--cc=anil.s.keshavamurthy@intel.com \
--cc=ardb@kernel.org \
--cc=davem@davemloft.net \
--cc=jbaron@akamai.com \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=naveen@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tz.stoyanov@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.