From: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
To: jikos@kernel.org, jic23@kernel.org, bentiss@kernel.org
Cc: linux-input@vger.kernel.org, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org, simeon@maryasin.name,
lixu.zhang@intel.com, crofts@kernel.org,
Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Subject: [PATCH v2 7/7] HID: sensor: hub: Remove clients before stopping hardware
Date: Wed, 4 Nov 2026 12:14:03 -0800 [thread overview]
Message-ID: <20261104201403.2039921-8-srinivas.pandruvada@linux.intel.com> (raw)
In-Reply-To: <20261104201403.2039921-1-srinivas.pandruvada@linux.intel.com>
Remove MFD clients before stopping the HID hardware so their close calls
remain valid. Runtime-PM teardown may cancel a pending autosuspend without
running the client suspend callback, leaving hub references after child
removal.
Clients share one HID open while ref_cnt is nonzero. After removing the
children, drain any remaining references and call hid_hw_close() once if
the count is nonzero. Then stop the HID hardware. This avoids both a
leaked open and the underflow caused by an unconditional close.
The pending-request walk runs before hid_hw_stop() disconnects HID-core
children such as hidraw. Skip non-platform children and platform children
without sensor-hub data before checking pending request state.
Fixes: 1df3a401154a ("HID: Delay opening HID device")
Reported-by: Семён Марьясин <simeon@maryasin.name>
Closes: https://lore.kernel.org/all/CAM2dg7ewfVJSP4rFyhkCB1Rmd1+X56sAg=eUdbPthG2xrLqwQQ@mail.gmail.com/
Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
drivers/hid/hid-sensor-hub.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
index 0c4884c5821f..e9d6eb3b3831 100644
--- a/drivers/hid/hid-sensor-hub.c
+++ b/drivers/hid/hid-sensor-hub.c
@@ -10,6 +10,7 @@
#include <linux/slab.h>
#include <linux/mfd/core.h>
#include <linux/list.h>
+#include <linux/platform_device.h>
#include <linux/hid-sensor-ids.h>
#include <linux/hid-sensor-hub.h>
#include "hid-ids.h"
@@ -806,7 +807,14 @@ static int sensor_hub_probe(struct hid_device *hdev,
static int sensor_hub_finalize_pending_fn(struct device *dev, void *data)
{
- struct hid_sensor_hub_device *hsdev = dev->platform_data;
+ struct hid_sensor_hub_device *hsdev;
+
+ if (!dev_is_platform(dev))
+ return 0;
+
+ hsdev = to_platform_device(dev)->dev.platform_data;
+ if (!hsdev)
+ return 0;
if (hsdev->pending.status)
complete(&hsdev->pending.ready);
@@ -820,8 +828,6 @@ static void sensor_hub_remove(struct hid_device *hdev)
unsigned long flags;
hid_dbg(hdev, " hardware removed\n");
- hid_hw_close(hdev);
- hid_hw_stop(hdev);
spin_lock_irqsave(&data->lock, flags);
device_for_each_child(&hdev->dev, NULL,
@@ -829,6 +835,14 @@ static void sensor_hub_remove(struct hid_device *hdev)
spin_unlock_irqrestore(&data->lock, flags);
mfd_remove_devices(&hdev->dev);
+ /* Clients share one HID open; release it if references remain. */
+ mutex_lock(&data->mutex);
+ if (data->ref_cnt) {
+ data->ref_cnt = 0;
+ hid_hw_close(hdev);
+ }
+ mutex_unlock(&data->mutex);
+ hid_hw_stop(hdev);
mutex_destroy(&data->mutex);
}
--
2.56.0
prev parent reply other threads:[~2026-11-04 20:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 20:13 [PATCH v2 0/7] HID: sensor: custom: use-after-freec after remove Srinivas Pandruvada
2026-11-04 20:13 ` [PATCH v2 1/7] HID: sensor: hub: Synchronize callback removal with raw events Srinivas Pandruvada
2026-11-04 20:13 ` [PATCH v2 2/7] HID: sensor: custom: Set owner for misc device Srinivas Pandruvada
2026-11-04 20:13 ` [PATCH v2 3/7] HID: sensor: custom: Disable sensor before hub close on removal Srinivas Pandruvada
2026-11-04 20:14 ` [PATCH v2 4/7] HID: sensor: custom: Fix state lifetime during removal Srinivas Pandruvada
2026-11-04 20:14 ` [PATCH v2 5/7] HID: sensor: custom: Serialize misc device reads Srinivas Pandruvada
2026-11-04 20:14 ` [PATCH v2 6/7] HID: sensor: custom: Register enable attribute after misc device Srinivas Pandruvada
2026-11-04 20:14 ` Srinivas Pandruvada [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=20261104201403.2039921-8-srinivas.pandruvada@linux.intel.com \
--to=srinivas.pandruvada@linux.intel.com \
--cc=bentiss@kernel.org \
--cc=crofts@kernel.org \
--cc=jic23@kernel.org \
--cc=jikos@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lixu.zhang@intel.com \
--cc=simeon@maryasin.name \
/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®