mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rosen Penev <rosenp@gmail.com>
To: "Pali Rohár" <pali@kernel.org>,
	"Hans de Goede" <hansg@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Darren Hart" <dvhart@linux.intel.com>
Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] platform/x86: dell-rbtn: Serialize access to the rfkill device
Date: Fri, 13 Nov 2026 22:25:13 -0800	[thread overview]
Message-ID: <bcae17e45257dc32f4b9af20e1760dd3f7fff46f.1794633181.git.rosenp@gmail.com> (raw)

For slider type devices, the rfkill device is created and destroyed
from rbtn_switch_dev() whenever the first notifier is registered or
the last one is unregistered, i.e. when dell-laptop is loaded or
unloaded. rbtn_notify() runs from the ACPI notify workqueue at the
same time and does

	if (rbtn_data->rfkill)
		rbtn_rfkill_query(rbtn_data->rfkill, ...);

with no locking. If the slider is toggled while dell-laptop is being
loaded, rbtn_rfkill_exit() can unregister and free the rfkill device
between the check and its use.

Add a per-device mutex around creating, destroying and querying the
rfkill device. All three run in process context. The rfkill core only
calls back into .query and .set_block, which do not take the new lock.

Fixes: b05ffc95f9ed ("dell-rbtn: Export notifier for other kernel modules")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
Developed with the help of an AI coding assistant (Claude Opus 5.5),
which found the issue and drafted the fix; I reviewed it and am
responsible for it. Builds cleanly with W=1.
Tested on a Dell Precision M4800 running v7.2.15, using the equivalent
backports built as out-of-tree modules: the dell-wifi and dell-bluetooth rfkill devices are
registered and unload/reload with dell-laptop is clean. The race
itself was not reproduced.

 drivers/platform/x86/dell/dell-rbtn.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/platform/x86/dell/dell-rbtn.c b/drivers/platform/x86/dell/dell-rbtn.c
index c0b3877bb27d..a38bd84bac5a 100644
--- a/drivers/platform/x86/dell/dell-rbtn.c
+++ b/drivers/platform/x86/dell/dell-rbtn.c
@@ -5,10 +5,12 @@
 
 */
 
+#include <linux/cleanup.h>
 #include <linux/module.h>
 #include <linux/acpi.h>
 #include <linux/rfkill.h>
 #include <linux/input.h>
+#include <linux/mutex.h>
 #include <linux/platform_device.h>
 
 #include "dell-rbtn.h"
@@ -21,6 +23,7 @@ enum rbtn_type {
 
 struct rbtn_data {
 	enum rbtn_type type;
+	struct mutex rfkill_lock; /* protects rfkill */
 	struct rfkill *rfkill;
 	struct input_dev *input_dev;
 	bool suspended;
@@ -115,6 +118,8 @@ static int rbtn_rfkill_init(struct device *dev)
 	struct rbtn_data *rbtn_data = dev_get_drvdata(dev);
 	int ret;
 
+	guard(mutex)(&rbtn_data->rfkill_lock);
+
 	if (rbtn_data->rfkill)
 		return 0;
 
@@ -142,6 +147,8 @@ static void rbtn_rfkill_exit(struct device *dev)
 {
 	struct rbtn_data *rbtn_data = dev_get_drvdata(dev);
 
+	guard(mutex)(&rbtn_data->rfkill_lock);
+
 	if (!rbtn_data->rfkill)
 		return;
 
@@ -154,6 +161,8 @@ static void rbtn_rfkill_event(struct device *dev)
 {
 	struct rbtn_data *rbtn_data = dev_get_drvdata(dev);
 
+	guard(mutex)(&rbtn_data->rfkill_lock);
+
 	if (rbtn_data->rfkill)
 		rbtn_rfkill_query(rbtn_data->rfkill, ACPI_COMPANION(dev));
 }
@@ -415,6 +424,10 @@ static int rbtn_probe(struct platform_device *pdev)
 	if (!rbtn_data)
 		return -ENOMEM;
 
+	ret = devm_mutex_init(&pdev->dev, &rbtn_data->rfkill_lock);
+	if (ret)
+		return ret;
+
 	ret = rbtn_acquire(device, true);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Cannot enable device\n");

base-commit: 2800868f63227c8237d70c41e70d441c919620d6
-- 
2.56.0


                 reply	other threads:[~2026-11-14  6:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=bcae17e45257dc32f4b9af20e1760dd3f7fff46f.1794633181.git.rosenp@gmail.com \
    --to=rosenp@gmail.com \
    --cc=dvhart@linux.intel.com \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pali@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®