Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ledtrig-cpu: kill useless mutex to fix sleep in atomic context

Seeing the following every time the CPU enters or leaves idle on a
Beagleboard:

BUG: sleeping function called from invalid context at kernel/mutex.c:269
in_atomic(): 1, irqs_disabled(): 0, pid: 0, name: swapper/0
no locks held by swapper/0/0.
[<c001659c>] (unwind_backtrace+0x0/0xf8) from [<c05aaa7c>] (mutex_lock_nested+0x24/0x380)
[<c05aaa7c>] (mutex_lock_nested+0x24/0x380) from [<c043bd1c>] (ledtrig_cpu+0x38/0x88)
[<c043bd1c>] (ledtrig_cpu+0x38/0x88) from [<c000f4b0>] (cpu_idle+0xf4/0x120)
[<c000f4b0>] (cpu_idle+0xf4/0x120) from [<c07e47c8>] (start_kernel+0x2bc/0x30c)

Miles Lane has reported seeing similar splats during system suspend.

The mutex in struct led_trigger_cpu appears to have no function: it
resides in a per-cpu data structure which never changes after the
trigger is registered. So just remove it.

Reported-by: Miles Lane <miles.lane@gmail.com>
Signed-off-by: Nathan Lynch <ntl@pobox.com>
Signed-off-by: Bryan Wu <roc@roc-samos.(none)>

authored by

Nathan Lynch and committed by
Bryan Wu
0b8728d6 77b67063

-21
-21
drivers/leds/ledtrig-cpu.c
··· 33 33 struct led_trigger_cpu { 34 34 char name[MAX_NAME_LEN]; 35 35 struct led_trigger *_trig; 36 - struct mutex lock; 37 - int lock_is_inited; 38 36 }; 39 37 40 38 static DEFINE_PER_CPU(struct led_trigger_cpu, cpu_trig); ··· 47 49 void ledtrig_cpu(enum cpu_led_event ledevt) 48 50 { 49 51 struct led_trigger_cpu *trig = &__get_cpu_var(cpu_trig); 50 - 51 - /* mutex lock should be initialized before calling mutex_call() */ 52 - if (!trig->lock_is_inited) 53 - return; 54 - 55 - mutex_lock(&trig->lock); 56 52 57 53 /* Locate the correct CPU LED */ 58 54 switch (ledevt) { ··· 67 75 /* Will leave the LED as it is */ 68 76 break; 69 77 } 70 - 71 - mutex_unlock(&trig->lock); 72 78 } 73 79 EXPORT_SYMBOL(ledtrig_cpu); 74 80 ··· 107 117 for_each_possible_cpu(cpu) { 108 118 struct led_trigger_cpu *trig = &per_cpu(cpu_trig, cpu); 109 119 110 - mutex_init(&trig->lock); 111 - 112 120 snprintf(trig->name, MAX_NAME_LEN, "cpu%d", cpu); 113 121 114 - mutex_lock(&trig->lock); 115 122 led_trigger_register_simple(trig->name, &trig->_trig); 116 - trig->lock_is_inited = 1; 117 - mutex_unlock(&trig->lock); 118 123 } 119 124 120 125 register_syscore_ops(&ledtrig_cpu_syscore_ops); ··· 127 142 for_each_possible_cpu(cpu) { 128 143 struct led_trigger_cpu *trig = &per_cpu(cpu_trig, cpu); 129 144 130 - mutex_lock(&trig->lock); 131 - 132 145 led_trigger_unregister_simple(trig->_trig); 133 146 trig->_trig = NULL; 134 147 memset(trig->name, 0, MAX_NAME_LEN); 135 - trig->lock_is_inited = 0; 136 - 137 - mutex_unlock(&trig->lock); 138 - mutex_destroy(&trig->lock); 139 148 } 140 149 141 150 unregister_syscore_ops(&ledtrig_cpu_syscore_ops);