Skip to content

Commit 9e55f87

Browse files
committed
Merge branch 'locking-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull locking fixes from Thomas Gleixner: "A few fixes for lockdep: - initialize lockdep internal RCU head after initializing RCU - prevent use after free in a alloc_workqueue() error handling path - plug a memory leak in the workqueue core which fails to free a dynamically allocated lock name. - make Clang happy" * 'locking-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: workqueue, lockdep: Fix a memory leak in wq->lock_name workqueue, lockdep: Fix an alloc_workqueue() error path locking/lockdep: Only call init_rcu_head() after RCU has been initialized locking/lockdep: Avoid a Clang warning
2 parents 077d3da + 69a106c commit 9e55f87

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

kernel/locking/lockdep.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,9 @@ static bool class_lock_list_valid(struct lock_class *c, struct list_head *h)
842842
return true;
843843
}
844844

845-
static u16 chain_hlocks[];
845+
#ifdef CONFIG_PROVE_LOCKING
846+
static u16 chain_hlocks[MAX_LOCKDEP_CHAIN_HLOCKS];
847+
#endif
846848

847849
static bool check_lock_chain_key(struct lock_chain *chain)
848850
{
@@ -980,15 +982,22 @@ static inline void check_data_structures(void) { }
980982
*/
981983
static void init_data_structures_once(void)
982984
{
983-
static bool initialization_happened;
985+
static bool ds_initialized, rcu_head_initialized;
984986
int i;
985987

986-
if (likely(initialization_happened))
988+
if (likely(rcu_head_initialized))
989+
return;
990+
991+
if (system_state >= SYSTEM_SCHEDULING) {
992+
init_rcu_head(&delayed_free.rcu_head);
993+
rcu_head_initialized = true;
994+
}
995+
996+
if (ds_initialized)
987997
return;
988998

989-
initialization_happened = true;
999+
ds_initialized = true;
9901000

991-
init_rcu_head(&delayed_free.rcu_head);
9921001
INIT_LIST_HEAD(&delayed_free.pf[0].zapped);
9931002
INIT_LIST_HEAD(&delayed_free.pf[1].zapped);
9941003

kernel/workqueue.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3445,6 +3445,8 @@ static void wq_init_lockdep(struct workqueue_struct *wq)
34453445
lock_name = kasprintf(GFP_KERNEL, "%s%s", "(wq_completion)", wq->name);
34463446
if (!lock_name)
34473447
lock_name = wq->name;
3448+
3449+
wq->lock_name = lock_name;
34483450
lockdep_init_map(&wq->lockdep_map, lock_name, &wq->key, 0);
34493451
}
34503452

@@ -4291,6 +4293,8 @@ struct workqueue_struct *alloc_workqueue(const char *fmt,
42914293
return wq;
42924294

42934295
err_free_wq:
4296+
wq_unregister_lockdep(wq);
4297+
wq_free_lockdep(wq);
42944298
free_workqueue_attrs(wq->unbound_attrs);
42954299
kfree(wq);
42964300
return NULL;

0 commit comments

Comments
 (0)