From: Matthew Wilcox <willy@infradead.org>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org, Kees Cook <keescook@chromium.org>
Subject: [RFC] Saner typechecking for closures
Date: Tue, 23 Apr 2024 05:38:41 +0100 [thread overview]
Message-ID: <Zic7USbiliQtnKZr@casper.infradead.org> (raw)
What would you think to this?
+++ b/include/linux/delayed_call.h
@@ -14,13 +14,12 @@ struct delayed_call {
#define DEFINE_DELAYED_CALL(name) struct delayed_call name = {NULL, NULL}
-/* I really wish we had closures with sane typechecking... */
-static inline void set_delayed_call(struct delayed_call *call,
- void (*fn)(void *), void *arg)
-{
- call->fn = fn;
- call->arg = arg;
-}
+/* Typecheck the arg is appropriate for the function */
+#define set_delayed_call(call, _fn, _arg) do { \
+ (void)sizeof(_fn(_arg)); \
+ (call)->fn = (void (*)(void *))(_fn); \
+ (call)->arg = (_arg); \
+} while (0)
static inline void do_delayed_call(struct delayed_call *call)
{
That should give us the possibility of passing any pointer
to the function, but gets us away from void pointers. I did this as a
followup:
-extern void page_put_link(void *);
+extern void page_put_link(struct folio *);
...
-void page_put_link(void *arg)
+void page_put_link(struct folio *folio)
{
- put_page(arg);
+ folio_put(folio);
}
EXPORT_SYMBOL(page_put_link);
and similar changes to the three callers.
Or is there something newer and shinier we should be using instead of
delayed_call?
next reply other threads:[~2024-04-23 4:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-23 4:38 Matthew Wilcox [this message]
2024-04-24 23:01 ` [RFC] Saner typechecking for closures Kees Cook
2024-04-25 3:19 ` Al Viro
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=Zic7USbiliQtnKZr@casper.infradead.org \
--to=willy@infradead.org \
--cc=keescook@chromium.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).