[lkml]   [2015]   [Dec]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCHSET v2] ->follow_link() without dropping from RCU mode
On Fri, Dec 11 2015, Al Viro <> 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__));

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);


 \ /
  Last update: 2015-12-11 09:21    [W:0.104 / U:2.876 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site