All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Hans de Goede <hdegoede@redhat.com>,
	Andrzej Pietrasiewicz <andrzej.p@collabora.com>,
	ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] ACPI / button: fix handling lid state changes when input device closed
Date: Mon, 5 Oct 2020 13:29:05 +0200	[thread overview]
Message-ID: <CAJZ5v0jTXNYwLcUcaOHk89WVxWCZEZJhMUd94KBdsTK41Eo-5g@mail.gmail.com> (raw)
In-Reply-To: <20201005051125.GA3245495@dtor-ws>

On Mon, Oct 5, 2020 at 7:11 AM <dmitry.torokhov@gmail.com> wrote:
>
> The original intent of 84d3f6b76447 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: 84d3f6b76447 ("ACPI / button: Delay acpi_lid_initialize_state() until first user space open")
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>  drivers/acpi/button.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
> index 78cfc70cb320..b8dd51d8f96d 100644
> --- a/drivers/acpi/button.c
> +++ b/drivers/acpi/button.c
> @@ -154,6 +154,7 @@ struct acpi_button {
>         int last_state;
>         ktime_t last_time;
>         bool suspended;
> +       bool lid_state_initialized;
>  };
>
>  static struct acpi_device *lid_device;
> @@ -384,6 +385,8 @@ static int acpi_lid_update_state(struct acpi_device *device,
>
>  static void acpi_lid_initialize_state(struct acpi_device *device)
>  {
> +       struct acpi_button *button = acpi_driver_data(device);
> +
>         switch (lid_init_state) {
>         case ACPI_BUTTON_LID_INIT_OPEN:
>                 (void)acpi_lid_notify_state(device, 1);
> @@ -395,13 +398,14 @@ static void acpi_lid_initialize_state(struct acpi_device *device)
>         default:
>                 break;
>         }
> +
> +       button->lid_state_initialized = true;
>  }
>
>  static void acpi_button_notify(struct acpi_device *device, u32 event)
>  {
>         struct acpi_button *button = acpi_driver_data(device);
>         struct input_dev *input;
> -       int users;
>
>         switch (event) {
>         case ACPI_FIXED_HARDWARE_EVENT:
> @@ -410,10 +414,7 @@ static void acpi_button_notify(struct acpi_device *device, u32 event)
>         case ACPI_BUTTON_NOTIFY_STATUS:
>                 input = button->input;
>                 if (button->type == ACPI_BUTTON_TYPE_LID) {
> -                       mutex_lock(&button->input->mutex);
> -                       users = button->input->users;
> -                       mutex_unlock(&button->input->mutex);
> -                       if (users)
> +                       if (button->lid_state_initialized)
>                                 acpi_lid_update_state(device, true);
>                 } else {
>                         int keycode;
> @@ -458,7 +459,7 @@ static int acpi_button_resume(struct device *dev)
>         struct acpi_button *button = acpi_driver_data(device);
>
>         button->suspended = false;
> -       if (button->type == ACPI_BUTTON_TYPE_LID && button->input->users) {
> +       if (button->type == ACPI_BUTTON_TYPE_LID) {
>                 button->last_state = !!acpi_lid_evaluate_state(device);
>                 button->last_time = ktime_get();
>                 acpi_lid_initialize_state(device);
> --

Applied as 5.10 material with the R-by from Hans, thanks!

      parent reply	other threads:[~2020-10-05 11:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-05  5:11 [PATCH] ACPI / button: fix handling lid state changes when input device closed dmitry.torokhov
2020-10-05  8:05 ` Hans de Goede
2020-10-05 11:29 ` Rafael J. Wysocki [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJZ5v0jTXNYwLcUcaOHk89WVxWCZEZJhMUd94KBdsTK41Eo-5g@mail.gmail.com \
    --to=rafael@kernel.org \
    --cc=andrzej.p@collabora.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=hdegoede@redhat.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.