Skip to content

Commit 21988a8

Browse files
dtorrafaeljw
authored andcommitted
ACPI: button: fix handling lid state changes when input device closed
The original intent of 84d3f6b was to delay evaluating lid state until all drivers have been loaded, with input device being opened from userspace serving as a signal for this condition. Let's ensure that state updates happen even if userspace closed (or in the future inhibited) input device. Note that if we go through suspend/resume cycle we assume the system has been fully initialized even if LID input device has not been opened yet. This has a side-effect of fixing access to input->users outside of input->mutex protections by the way of eliminating said accesses and using driver private flag. Fixes: 84d3f6b ("ACPI / button: Delay acpi_lid_initialize_state() until first user space open") Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Cc: 4.15+ <stable@vger.kernel.org> # 4.15+ Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 549738f commit 21988a8

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

drivers/acpi/button.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ struct acpi_button {
153153
int last_state;
154154
ktime_t last_time;
155155
bool suspended;
156+
bool lid_state_initialized;
156157
};
157158

158159
static struct acpi_device *lid_device;
@@ -383,6 +384,8 @@ static int acpi_lid_update_state(struct acpi_device *device,
383384

384385
static void acpi_lid_initialize_state(struct acpi_device *device)
385386
{
387+
struct acpi_button *button = acpi_driver_data(device);
388+
386389
switch (lid_init_state) {
387390
case ACPI_BUTTON_LID_INIT_OPEN:
388391
(void)acpi_lid_notify_state(device, 1);
@@ -394,13 +397,14 @@ static void acpi_lid_initialize_state(struct acpi_device *device)
394397
default:
395398
break;
396399
}
400+
401+
button->lid_state_initialized = true;
397402
}
398403

399404
static void acpi_button_notify(struct acpi_device *device, u32 event)
400405
{
401406
struct acpi_button *button = acpi_driver_data(device);
402407
struct input_dev *input;
403-
int users;
404408

405409
switch (event) {
406410
case ACPI_FIXED_HARDWARE_EVENT:
@@ -409,10 +413,7 @@ static void acpi_button_notify(struct acpi_device *device, u32 event)
409413
case ACPI_BUTTON_NOTIFY_STATUS:
410414
input = button->input;
411415
if (button->type == ACPI_BUTTON_TYPE_LID) {
412-
mutex_lock(&button->input->mutex);
413-
users = button->input->users;
414-
mutex_unlock(&button->input->mutex);
415-
if (users)
416+
if (button->lid_state_initialized)
416417
acpi_lid_update_state(device, true);
417418
} else {
418419
int keycode;
@@ -457,7 +458,7 @@ static int acpi_button_resume(struct device *dev)
457458
struct acpi_button *button = acpi_driver_data(device);
458459

459460
button->suspended = false;
460-
if (button->type == ACPI_BUTTON_TYPE_LID && button->input->users) {
461+
if (button->type == ACPI_BUTTON_TYPE_LID) {
461462
button->last_state = !!acpi_lid_evaluate_state(device);
462463
button->last_time = ktime_get();
463464
acpi_lid_initialize_state(device);

0 commit comments

Comments
 (0)