[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87io45zapn.fsf@rasmusvillemoes.dk>
Date: Fri, 11 Dec 2015 08:49:24 +0100
From: Rasmus Villemoes <linux@...musvillemoes.dk>
To: Al Viro <viro@...IV.linux.org.uk>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
linux-fsdevel <linux-fsdevel@...r.kernel.org>,
Neil Brown <neilb@...e.com>
Subject: Re: [PATCHSET v2] ->follow_link() without dropping from RCU mode
On Fri, Dec 11 2015, Al Viro <viro@...IV.linux.org.uk> wrote:
> I would really love to be able to say
> set_delayed_call(done, kfree, p);
> but as it is I had to keep a wrapper - void kfree_link(void *). The problem
> is, you can't assign void f(const void *) to void (*p)(void *) - mismatch of
> qualifiers in the arguments makes the latter not assignment-compatible with
> the former. If there's a clever trick allowing to sidestep that, I'd be
> very happy; I don't know one. Any ideas not starting with "use C11" (or,
> worse yet, "use such and such C++ misfeature with arseloads of RTL required
> in order to implement it") would be welcome...
I _think_ this satisfies these very reasonable criteria. What you're
looking for is presumably __attribute__((__transparent_union__)). At
least this compiles without warnings at -Wall -Wextra and gives the
expected disassembly, and the gcc docs mention transparent_union at
least back to 4.0.4.
#include <stddef.h>
struct delayed_call {
void (*fn)(void *);
void *arg;
};
union delayed_call_fn {
void (*fn)(void *);
void (*kfree_like)(const void *);
} __attribute__((__transparent_union__));
void
set_delayed_call(struct delayed_call *call, union delayed_call_fn u, void *arg)
{
call->fn = u.fn;
call->arg = arg;
}
void some_cb(void *);
void kfree(const void *);
extern struct delayed_call done;
void test(void)
{
set_delayed_call(&done, some_cb, NULL);
set_delayed_call(&done, kfree, NULL);
}
Rasmus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists