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=1796380177; b=4O9t6EO6zFqZgvowRTk6MIbgVUyanl6NQHUgX7K9ZBiL33rQJDsE9RyAQZAz1KqKCBJb CtFEHg6MV6cq/FvDuFvDOuZ/zgNBiWGHJKLqUKxdFV8qb0t4JbPrdHGsE5OKcCtKYv+by r5/6oXXufjghgDMLeFUw31IN78yKfqeMR2NQIn/XTW2C4iKanCUfQd/WS6CFgA811GTzT omMOjAhHyUjaaLszuP/3kzuNlRDireaTdqpwZbgYWJJAoIHkkwFPbD/Sr8jCUTwE7cx5+ OsFQCS5CsA4+kwFarx+L9e8BAJARO1Wl0bbhcYTnpCMvYdIDiPQ3LirkuKJZEayPiig== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380177; 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=zXSaOR0y/2m93z9XuwgeVvNa8nSEhknLRcltY6okxJc=; b=AjshqEk5feOklknqDT61n7dxMWfQ95RAW5jrDsbpn4mUeFHnMozXrcf6Eo5u4jqf2AHE g6bca84yWkVaJF07XIlBT09haKjP4PF2nZmVUR7XUajilaG5bj/Qngn/7oELUXgyF5Ixe rjqM0EcGRE9IfD1pq9KSbSplTyhYl+sjsofeDgPmeSN5CeSab40+Dky1HL7ThUvkVuHfI Upp7fPIWIlmY3caCS/Fb0f6J+ZSmwx3gkbzYAz/H5J4evCvEDMsGSCvDujOKsgkgVm4/q ZX5Up/PxJ9EIBGTk9Z9Ziw1p2qvL9EKWlX1OzhmlN32GGRb9tizUNCOPhHULlCUT0vA== 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="MApk/dnL"; 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 80A4D606A32F; Fri, 4 Dec 2026 10:29:37 +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=MApk/dnL Received: by smtp.kernel.org (Postfix) with ESMTPSA id F33251F0092C; Fri, 4 Dec 2026 10:29:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380177; bh=zXSaOR0y/2m93z9XuwgeVvNa8nSEhknLRcltY6okxJc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MApk/dnLgPcplpI9a6rFQf5bw011jGPH4cW+182+RPkFZqRXTQlcwtgLn491d3RYu pcPca04yMlFC5JBgWzn/rz73ijoMNa6dhFIFqIrnDJ3L6DHPpfJY75DV3f4HiwGJ+/ FsHvrhNqi56GvVqiMBrwitymj3aOHTfqNGttRx/4= 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 7.3 160/742] HID: sensor-hub: Remove clients before stopping hardware Date: Fri, 4 Dec 2026 19:00:24 +0900 Message-ID: <20261204100639.365307189@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-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 0c4884c5821fd..e9d6eb3b38314 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" @@ -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.53.0