From: Johannes Berg <johannes@sipsolutions.net>
To: Jakub Sitnicki <jakub@cloudflare.com>
Cc: Jakub Kicinski <kuba@kernel.org>,
netdev@vger.kernel.org, Peter Zijlstra <peterz@infradead.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/3] using guard/__free in networking
Date: Wed, 27 Mar 2024 22:43:33 +0100 [thread overview]
Message-ID: <e6fabaa541704463804f48b5931e8a43f7ee75eb.camel@sipsolutions.net> (raw)
In-Reply-To: <0e7af4cb0dc19be7cc0267256284a70ceb250b38.camel@sipsolutions.net>
On Wed, 2024-03-27 at 22:28 +0100, Johannes Berg wrote:
>
> +typedef struct class_##_name##_drop##_t { \
> + class_##_name##_t obj; \
> + void (*destructor)(struct class_##_name##_drop##_t *); \
> +} class_##_name##_drop##_t; \
No, I misread the compiler output, it does output a real destructor
function to push it into a stack variable with this...
So I guess it'd have to be
void my_something(my_t *my)
{
...
named_guard(lock, mutex)(&my->mutex);
...
if (foo)
return -EINVAL; // automatically unlocks
...
// no need for lock any more
drop_guard(lock, mutex);
...
// do other things now unlocked
}
instead, syntax-wise.
Which obviously simplifies the changes:
diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h
index c2d09bc4f976..cf39a4a3f56f 100644
--- a/include/linux/cleanup.h
+++ b/include/linux/cleanup.h
@@ -163,6 +163,12 @@ static inline class_##_name##_t class_##_name##ext##_constructor(_init_args) \
#define guard(_name) \
CLASS(_name, __UNIQUE_ID(guard))
+#define named_guard(_name, _class) \
+ CLASS(_class, _name)
+
+#define drop_guard(_name, _class) \
+ do { class_##_class##_destructor(&_name); _name = NULL; } while (0)
+
#define __guard_ptr(_name) class_##_name##_lock_ptr
#define scoped_guard(_name, args...) \
prev parent reply other threads:[~2024-03-27 21:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20240325223905.100979-5-johannes@sipsolutions.net>
[not found] ` <20240325190957.02d74258@kernel.org>
[not found] ` <8eeae19a0535bfe72f87ee8c74a15dd2e753c765.camel@sipsolutions.net>
[not found] ` <20240326073722.637e8504@kernel.org>
[not found] ` <0dc633a36a658b96f9ec98165e7db61a176c79e0.camel@sipsolutions.net>
[not found] ` <87h6grbevf.fsf@cloudflare.com>
2024-03-27 21:28 ` Johannes Berg
2024-03-27 21:43 ` Johannes Berg [this message]
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=e6fabaa541704463804f48b5931e8a43f7ee75eb.camel@sipsolutions.net \
--to=johannes@sipsolutions.net \
--cc=jakub@cloudflare.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=peterz@infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®