infra: fix racy NULL deref on thread termination

This commit is contained in:
Thomas Schoebel-Theuer 2014-11-05 14:30:14 +01:00
parent 2b2e07d24d
commit b0171749a4
1 changed files with 7 additions and 6 deletions

View File

@ -652,12 +652,13 @@ extern void brick_thread_stop_nowait(struct task_struct *k);
#define brick_thread_stop(_thread) \ #define brick_thread_stop(_thread) \
do { \ do { \
if (likely(_thread)) { \ struct task_struct *__thread__ = (_thread); \
BRICK_INF("stopping thread '%s'\n", (_thread)->comm); \ if (likely(__thread__)) { \
kthread_stop(_thread); \ BRICK_INF("stopping thread '%s'\n", __thread__->comm); \
BRICK_INF("thread '%s' finished.\n", (_thread)->comm); \ kthread_stop(__thread__); \
remove_binding(_thread); \ BRICK_INF("thread '%s' finished.\n", __thread__->comm); \
put_task_struct(_thread); \ remove_binding(__thread__); \
put_task_struct(__thread__); \
_thread = NULL; \ _thread = NULL; \
} \ } \
} while (0) } while (0)