From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796383424; b=zw7nT8c6sYZ/biaLVdiJ1Q3KqKZTpVCXGoP0lIt6/bpAvlpsQiWTob/S/KH0ZSqxxJ7q crhaH/2n2ajFHIR3xcYdu48wG6pyo6c0YepNLYe0HaEXsXU8dDqsyk9XMXDY0QosxbFfG RP7UPPUBqxCCniu5rk+IWfZ/uxSPMwf4TolsjKGgLADK92kN/O7Ghq0y2oif77144+cpJ 7iPzIiyDcLRCLmPGM0+9QP2bnMUXkLeZ5SObkeVt0JsK4wtIkCSzQWy5drGElYLTCtkQU 6Mb+oIqEMqXkHDq2srl1YD0uZ5POLWnpyh93aZpVMbGec61hpTTuuM5udJqyqPk0nJw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383424; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=sBGZcWPBW/sKKF/OHUCPlnv8APxlgljiAu+PlN43Mvw=; b=JhyEuKS3ZWTzD6Xd6I9GjW72mCsjuPKc/109zsLF5AMSYVo+/LZCByBxjWFCqQ54l0sr l7Lxw7rcLA+pr81UgA0YgKl0PK3Ir+avTaUGNQn6dX/x02j754WyIuEPzIjpfkiJcFOX+ 9Q54GB2WPyZpQTnQgYY8PFm0Tv59LAd/zZZ9+eX+te3zwzC8pZ1eH+GzU28SfidFesRcz RbD4xHTtwhvnPs7RTTtBGdcS8oMEhUEj9Tjpy0ksWeRWDUw7U1LHjCI99O95XZZW3vFku Fdro/tJFM10/ayuhQqJ8Z8IuW0P+bFc5U+naJJptIFnRtbZDPMajEswg67qxK8I9Isg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=NEC9MiWB; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F7AF606A335; Fri, 4 Dec 2026 11:23:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=NEC9MiWB Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E5141F00933; Fri, 4 Dec 2026 11:23:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383423; bh=sBGZcWPBW/sKKF/OHUCPlnv8APxlgljiAu+PlN43Mvw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=NEC9MiWBlJ975eRKvxTT5VmUvbR4W/r/C3YRVN0GW3n7Xi8L8p9cqBO7aXgC6JNhY AsHjZgBQtYtY3lf8UISKvFISF/pv6prgvh0sgEfDZ6461rkIkHBJt/3dAz5+iQjJHh ygwhtTh3y0TBDNRzkSqzsN+DTL/MD2yGCHCYojMI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Semyon Maryasin , Zhang Lixu , Srinivas Pandruvada , Jonathan Cameron , Jiri Kosina , Sasha Levin Subject: [PATCH 6.12 219/555] HID: sensor-hub: Remove clients before stopping hardware Date: Fri, 4 Dec 2026 19:04:22 +0900 Message-ID: <20261204100617.342133829@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Srinivas Pandruvada [ Upstream commit 41cb3076a221afba052ae1624ccf62e500706b20 ] 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: Semyon Maryasin Closes: https://lore.kernel.org/all/CAM2dg7ewfVJSP4rFyhkCB1Rmd1+X56sAg=eUdbPthG2xrLqwQQ@mail.gmail.com/ Tested-by: Semyon Maryasin Tested-by: Zhang Lixu Signed-off-by: Srinivas Pandruvada Reviewed-by: Jonathan Cameron Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- 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 9f14439cc0788..e9eb32f15f091 100644 --- a/drivers/hid/hid-sensor-hub.c +++ b/drivers/hid/hid-sensor-hub.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include "hid-ids.h" @@ -808,7 +809,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); @@ -822,8 +830,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, @@ -831,6 +837,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.53.0