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

Input: i8042 - enable wakeup on a stable struct device

We don't know when the device will be added with device_add() in
serio_add_port() because serio_add_port() is called from a workqueue
that this driver schedules by calling serio_register_port(). The best we
can know is that the device will definitely not have been added yet when
the start callback is called on the serio device.

While it hasn't been shown to be a problem, proactively move the wakeup
enabling calls to the start hook so that we don't race with the
workqueue calling device_add(). This will avoid racy situations where
code tries to add wakeup sysfs attributes for this device from
dpm_sysfs_add() but the path in device_set_wakeup_capable() has already
done so.

Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Stephen Boyd and committed by
Dmitry Torokhov
c8a144b2 53119e51

+14 -11
+14 -11
drivers/input/serio/i8042.c
··· 432 432 { 433 433 struct i8042_port *port = serio->port_data; 434 434 435 + device_set_wakeup_capable(&serio->dev, true); 436 + 437 + /* 438 + * On platforms using suspend-to-idle, allow the keyboard to 439 + * wake up the system from sleep by enabling keyboard wakeups 440 + * by default. This is consistent with keyboard wakeup 441 + * behavior on many platforms using suspend-to-RAM (ACPI S3) 442 + * by default. 443 + */ 444 + if (pm_suspend_default_s2idle() && 445 + serio == i8042_ports[I8042_KBD_PORT_NO].serio) { 446 + device_set_wakeup_enable(&serio->dev, true); 447 + } 448 + 435 449 spin_lock_irq(&i8042_lock); 436 450 port->exists = true; 437 451 spin_unlock_irq(&i8042_lock); ··· 1411 1397 (unsigned long) I8042_COMMAND_REG, 1412 1398 i8042_ports[i].irq); 1413 1399 serio_register_port(serio); 1414 - device_set_wakeup_capable(&serio->dev, true); 1415 - 1416 - /* 1417 - * On platforms using suspend-to-idle, allow the keyboard to 1418 - * wake up the system from sleep by enabling keyboard wakeups 1419 - * by default. This is consistent with keyboard wakeup 1420 - * behavior on many platforms using suspend-to-RAM (ACPI S3) 1421 - * by default. 1422 - */ 1423 - if (pm_suspend_default_s2idle() && i == I8042_KBD_PORT_NO) 1424 - device_set_wakeup_enable(&serio->dev, true); 1425 1400 } 1426 1401 } 1427 1402