Re: [PATCH 03/10] sched/headers: Make task_struct::wake_q an opaque pointer

From: Linus Torvalds
Date: Wed Feb 08 2017 - 15:01:06 EST


On Wed, Feb 8, 2017 at 10:34 AM, Ingo Molnar <mingo@xxxxxxxxxx> wrote:
> To be able to decouple wake_q functionality from <linux/sched.h> make
> the basic task_struct::wake_q pointer an opaque void *.

Please don't use "void *" for opaque pointers.

You lose all typechecking, and this is just complete garbage:

+ struct wake_q_node *node = (void *)&task->wake_q;

What? You're casting a "void *" to "void *"? WTF?

The proper way to do opaque pointers is to declare them as pointers to
a structure that hasn't been defined (ie use a "struct xyz;" forward
declaration), and then that structure is only actually defined in the
places that use the otherwise opaque pointer.

That way you

(a) never need to cast anything

(b) get proper (and strong) type checking for the pointers.

and the people who need to look into it automatically do the right
thing, while anybody else who tries to dereference or otherwise use
the struct pointer will get a compiler error.

Linus