Bug 3863 - init_wait macro in <linux/wait.h> needs parens
Summary: init_wait macro in <linux/wait.h> needs parens
Alias: None
Product: Drivers
Classification: Unclassified
Component: Other (show other bugs)
Hardware: i386 Linux
: P2 low
Assignee: drivers_other
Depends on:
Reported: 2004-12-04 11:30 UTC by david howard
Modified: 2004-12-22 09:32 UTC (History)
0 users

See Also:
Kernel Version: 2.6.7
Tree: Mainline
Regression: ---


Description david howard 2004-12-04 11:30:41 UTC
Distribution: fedora
Hardware Environment: dell pentium 4 pc
Software Environment: gcc
Problem Description: the init_wait macro in <linux/wait.h> needs to parenthesize
the uses of the argument 'wait' or compile errors and even unwanted side effects
could occur

Steps to reproduce a compile error
   wait_queue_t wq;
   wait_queue_t *pq;
   init_wait(&wq); // fails compilation because -> binds before & in this case
   init_wait((&wq)); // ok
   pq = &wq;
   init_wait(pq); // ok

a side effect (and failure to properly init the wait) could conceivably occur if
the wait_queue_t was in a higher level data structure and the operator binding
just happened to resolve to a like variable name such as 'current' but not the
right one, and no compile error is issued. this is more unlikely because all 3
variables would have to be there or at least one will complain.
Comment 1 david howard 2004-12-04 11:32:45 UTC
#define init_wait(wait)                                                 \
        do {                                                            \
                wait->task = current;                                   \
                wait->func = autoremove_wake_function;                  \
                INIT_LIST_HEAD(&wait->task_list);                       \
        } while (0)


#define init_wait(wait)                                                 \
        do {                                                            \
                (wait)->task = current;                                   \
                (wait)->func = autoremove_wake_function;                  \
                INIT_LIST_HEAD(&(wait)->task_list);                       \
        } while (0)
Comment 2 Vadim Lobanov 2004-12-16 20:35:47 UTC
Andrew Morton plans to have a patch available in the post-2.6.10 timeframe. No 
bug left behind. :)
Comment 3 Alexander Nyberg 2004-12-22 09:32:27 UTC
Patch has hit linus tree.

Note You need to log in before you can comment on or make changes to this bug.