All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Mark Pearson" <mpearson-lenovo@squebb.ca>
To: "Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
	"Henrique de Moraes Holschuh" <hmh@hmh.eng.br>,
	"Derek J . Clark" <derekjohn.clark@gmail.com>,
	"Rong Zhang" <i@rong.moe>, "Hans de Goede" <hansg@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: "platform-driver-x86@vger.kernel.org"
	<platform-driver-x86@vger.kernel.org>,
	ibm-acpi-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/8] platform/x86: thinkpad_acpi: simplify hotkey open/close and poll setup
Date: Thu, 26 Nov 2026 22:28:27 -0500	[thread overview]
Message-ID: <c1fccfb9-edfd-4287-a8dd-6cd9f51170ff@app.fastmail.com> (raw)
In-Reply-To: <20261125-thinkpad-acpi-hotkey-poll-v1-3-6dee57519c2e@gmail.com>

On Wed, Nov 25, 2026, at 6:11 PM, Dmitry Torokhov wrote:
> Since commit 38b9ab80db31 ("platform/x86: thinkpad_acpi: Move subdriver
> initialization to tpacpi_pdriver's probe."), tpacpi_subdrivers_release()
> is registered via devm_add_action_or_reset() before tpacpi_inputdev is
> registered. Because devres resources are unwound in reverse order,
> tpacpi_inputdev is always unregistered (closing any open handles and
> preventing new opens) before hotkey_exit() is called. Combined with
> hotkey_kthread() no longer exiting early on TPACPI_LIFE_EXITING, the
> lifecycle guards in the input callbacks are unnecessary.
>
> Drop the obsolete tpacpi_lifecycle checks and BUG() from
> hotkey_inputdev_open() and hotkey_inputdev_close(), as well as the
> redundant driver mask check in hotkey_inputdev_close() (which
> hotkey_poll_setup() already evaluates).
>
> Also call hotkey_poll_setup() directly inside the existing hotkey_mutex
> critical sections in hotkey_init() and hotkey_resume(), and remove the
> now-unused hotkey_poll_setup_safe() wrapper.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>  drivers/platform/x86/lenovo/thinkpad_acpi.c | 52 +++++++++--------------------
>  1 file changed, 15 insertions(+), 37 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c 
> b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> index 659a2c5d1982..e5f78107bd1a 100644
> --- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> +++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> @@ -2546,12 +2546,6 @@ static void hotkey_poll_setup(const bool 
> may_warn)
>  	}
>  }
> 
> -static void hotkey_poll_setup_safe(const bool may_warn)
> -{
> -	guard(mutex)(&hotkey_mutex);
> -	hotkey_poll_setup(may_warn);
> -}
> -
>  static void hotkey_poll_set_freq(unsigned int freq)
>  {
>  	lockdep_assert_held(&hotkey_mutex);
> @@ -2568,10 +2562,6 @@ static void hotkey_poll_setup(const bool __unused)
>  {
>  }
> 
> -static void hotkey_poll_setup_safe(const bool __unused)
> -{
> -}
> -
>  static void hotkey_poll_stop_sync(void)
>  {
>  }
> @@ -2579,21 +2569,12 @@ static void hotkey_poll_stop_sync(void)
> 
>  static int hotkey_inputdev_open(struct input_dev *dev)
>  {
> -	switch (tpacpi_lifecycle) {
> -	case TPACPI_LIFE_INIT:
> -	case TPACPI_LIFE_RUNNING:
> -		scoped_guard(mutex, &hotkey_mutex) {
> -			hotkey_input_enabled = true;
> -			hotkey_poll_setup(false);
> -		}
> -		return 0;
> -	case TPACPI_LIFE_EXITING:
> -		return -EBUSY;
> -	}
> +	guard(mutex)(&hotkey_mutex);
> +
> +	hotkey_input_enabled = true;
> +	hotkey_poll_setup(false);
> 
> -	/* Should only happen if tpacpi_lifecycle is corrupt */
> -	BUG();
> -	return -EBUSY;
> +	return 0;
>  }
> 
>  static void hotkey_inputdev_close(struct input_dev *dev)
> @@ -2601,11 +2582,7 @@ static void hotkey_inputdev_close(struct input_dev *dev)
>  	guard(mutex)(&hotkey_mutex);
> 
>  	hotkey_input_enabled = false;
> -
> -	/* disable hotkey polling when possible */
> -	if (tpacpi_lifecycle != TPACPI_LIFE_EXITING &&
> -	    !(hotkey_source_mask & hotkey_driver_mask))
> -		hotkey_poll_setup(false);
> +	hotkey_poll_setup(false);
>  }
> 
>  /* sysfs hotkey enable 
> ------------------------------------------------- */
> @@ -3571,22 +3548,23 @@ static int __init hotkey_init(struct 
> ibm_init_struct *iibm)
>  		res = hotkey_mask_set(((hotkey_all_mask & ~hotkey_reserved_mask)
>  				       | hotkey_driver_mask)
>  				      & ~hotkey_source_mask);
> +		if (!res) {
> +			hotkey_user_mask = (hotkey_acpi_mask | hotkey_source_mask)
> +						& ~hotkey_reserved_mask;
> +			vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
> +				    "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n",
> +				    hotkey_user_mask, hotkey_acpi_mask, hotkey_source_mask);
> +			hotkey_poll_setup(true);
> +		}
>  	}
>  	if (res) {
>  		hotkey_exit();
>  		return res;
>  	}
> -	hotkey_user_mask = (hotkey_acpi_mask | hotkey_source_mask)
> -				& ~hotkey_reserved_mask;
> -	vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
> -		"initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n",
> -		hotkey_user_mask, hotkey_acpi_mask, hotkey_source_mask);
> 
>  	tpacpi_inputdev->open = &hotkey_inputdev_open;
>  	tpacpi_inputdev->close = &hotkey_inputdev_close;
> 
> -	hotkey_poll_setup_safe(true);
> -
>  	/* Enable TrackPoint doubletap event reporting by default. */
>  	tp_features.trackpoint_doubletap_enable = 1;
> 
> @@ -4024,6 +4002,7 @@ static void hotkey_resume(void)
>  		if (hotkey_status_set(true) < 0 ||
>  		    hotkey_mask_set(hotkey_acpi_mask) < 0)
>  			pr_err("error while attempting to reset the event firmware interface\n");
> +		hotkey_poll_setup(false);
>  	}
> 
>  	tpacpi_send_radiosw_update();
> @@ -4033,7 +4012,6 @@ static void hotkey_resume(void)
>  	keyboard_attached_on_screen_notify_change();
>  	hotkey_wakeup_reason_notify_change();
>  	hotkey_wakeup_hotunplug_complete_notify_change();
> -	hotkey_poll_setup_safe(false);
> 
>  	/* restore previous mode of adaptive keyboard of X1 Carbon */
>  	if (tp_features.has_adaptive_kbd) {
>
> -- 
> 2.56.1.839.g22a8290db9-goog

I think this is all good.
Just to check - how much testing have you done? I'll see if I can put the series through a few platforms just in case (but I can't see any issues with the code)

Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Mark

  reply	other threads:[~2026-11-27  3:28 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 23:11 [PATCH 0/8] platform/x86: thinkpad_acpi: clean up hotkey polling and locking Dmitry Torokhov
2026-11-25 23:11 ` [PATCH 1/8] platform/x86: thinkpad_acpi: remove early exit in hotkey_kthread() Dmitry Torokhov
2026-11-27  2:43   ` Mark Pearson
2026-11-25 23:11 ` [PATCH 2/8] platform/x86: thinkpad_acpi: drop dead -ENXIO check in hotkey_init() Dmitry Torokhov
2026-11-27  2:46   ` Mark Pearson
2026-11-25 23:11 ` [PATCH 3/8] platform/x86: thinkpad_acpi: simplify hotkey open/close and poll setup Dmitry Torokhov
2026-11-27  3:28   ` Mark Pearson [this message]
2026-11-29  6:00     ` Dmitry Torokhov
2026-11-25 23:11 ` [PATCH 4/8] platform/x86: thinkpad_acpi: update polling state in hotkey_user_mask_set() Dmitry Torokhov
2026-11-27  2:57   ` Mark Pearson
2026-11-25 23:11 ` [PATCH 5/8] platform/x86: thinkpad_acpi: use scoped_guard() for hotkey config locking Dmitry Torokhov
2026-11-27  3:01   ` Mark Pearson
2026-11-25 23:11 ` [PATCH 6/8] platform/x86: thinkpad_acpi: convert hotkey_thread_data_mutex to a spinlock Dmitry Torokhov
2026-11-27  3:35   ` Mark Pearson
2026-11-25 23:11 ` [PATCH 7/8] platform/x86: thinkpad_acpi: remove unused hotkey_poll_active flag Dmitry Torokhov
2026-11-27  3:02   ` Mark Pearson
2026-11-25 23:11 ` [PATCH 8/8] platform/x86: thinkpad_acpi: drop redundant input device parent assignment Dmitry Torokhov
2026-11-27  3:05   ` Mark Pearson
2026-11-27 13:25 ` [PATCH 0/8] platform/x86: thinkpad_acpi: clean up hotkey polling and locking Rong Zhang
2026-12-01 14:50 ` Ilpo Järvinen

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=c1fccfb9-edfd-4287-a8dd-6cd9f51170ff@app.fastmail.com \
    --to=mpearson-lenovo@squebb.ca \
    --cc=derekjohn.clark@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=hansg@kernel.org \
    --cc=hmh@hmh.eng.br \
    --cc=i@rong.moe \
    --cc=ibm-acpi-devel@lists.sourceforge.net \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    /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.