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

PM / wakeup: Fix sysfs registration error path

We shouldn't call wakeup_source_destroy() from the error path in
wakeup_source_register() because that calls __pm_relax() which takes a
lock that isn't initialized until wakeup_source_add() is called. Add a
new function, wakeup_source_free(), that just does the bare minimum to
free a wakeup source that was created but hasn't been added yet and use
it from the two places it's needed. This fixes the following problem
seen on various x86 server boxes:

INFO: trying to register non-static key.
the code is fine but needs lockdep annotation.
turning off the locking correctness validator.
CPU: 12 PID: 1 Comm: swapper/0 Not tainted 5.3.0-rc4-
Hardware name: HP ProLiant XL420 Gen9/ProLiant XL420 Gen9, BIOS U19 12/27/2015
Call Trace:
  dump_stack+0x62/0x9a
  register_lock_class+0x95a/0x960
  ? __platform_driver_probe+0xcd/0x230
  ? __platform_create_bundle+0xc0/0xe0
  ? i8042_init+0x4ec/0x578
  ? do_one_initcall+0xfe/0x45a
  ? kernel_init_freeable+0x614/0x6a7
  ? kernel_init+0x11/0x138
  ? ret_from_fork+0x35/0x40
  ? is_dynamic_key+0xf0/0xf0
  ? rwlock_bug.part.0+0x60/0x60
  ? __debug_check_no_obj_freed+0x8e/0x250
  __lock_acquire.isra.13+0x5f/0x830
  ? __debug_check_no_obj_freed+0x152/0x250
  lock_acquire+0x107/0x220
  ? __pm_relax.part.2+0x21/0xa0
  _raw_spin_lock_irqsave+0x35/0x50
  ? __pm_relax.part.2+0x21/0xa0
  __pm_relax.part.2+0x21/0xa0
  wakeup_source_destroy.part.3+0x18/0x190
  wakeup_source_register+0x43/0x50

Fixes: c8377adfa781 ("PM / wakeup: Show wakeup sources stats in sysfs")
Reported-by: Qian Cai <cai@lca.pw>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Stephen Boyd and committed by
Rafael J. Wysocki
ae367b79 c8377adf

+9 -4
+9 -4
drivers/base/power/wakeup.c
··· 137 137 spin_unlock_irqrestore(&deleted_ws.lock, flags); 138 138 } 139 139 140 + static void wakeup_source_free(struct wakeup_source *ws) 141 + { 142 + ida_free(&wakeup_ida, ws->id); 143 + kfree_const(ws->name); 144 + kfree(ws); 145 + } 146 + 140 147 /** 141 148 * wakeup_source_destroy - Destroy a struct wakeup_source object. 142 149 * @ws: Wakeup source to destroy. ··· 157 150 158 151 __pm_relax(ws); 159 152 wakeup_source_record(ws); 160 - ida_free(&wakeup_ida, ws->id); 161 - kfree_const(ws->name); 162 - kfree(ws); 153 + wakeup_source_free(ws); 163 154 } 164 155 EXPORT_SYMBOL_GPL(wakeup_source_destroy); 165 156 ··· 222 217 if (ws) { 223 218 ret = wakeup_source_sysfs_add(dev, ws); 224 219 if (ret) { 225 - wakeup_source_destroy(ws); 220 + wakeup_source_free(ws); 226 221 return NULL; 227 222 } 228 223 wakeup_source_add(ws);