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=1796381858; b=YzWCVI1cjITysEjmkSxf2FYWJ39oz+MOfX9YpdReHQr0/80Ou2auNypbjq5TRs8Ldn08 +PZxrTerc0fEZs+MzEI/0FzXKswHu8MRMFnaMOhGdVkIEj30UmCBlAFBNLGak5dsH206T Bgbf2y4FUzbntgn5UW49Ub8TQ4CqWhwXLB0N2htN0xxqr13y2ug0qdku3/SOyuHtB9Tqc FJ6PPn0CWR/PcAfGr3ec2BvgvIR7xGHD4ZEDHWlEt438dGqJjiisI+LityIwIuzK5AklN RTbqJ0G2bicLM+qs3Bk+EC+s8v12GHKbafWQ6fuIVDFPbd2FiZZxfC93XyQ1SCljP1A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381858; 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=yOHQHzS+U8vNbPjJ5K0bx1+6j+C3tTGQNqPyNNgcn1U=; b=Ig4iB7pMLGnPB4TAW1VyftBiZxEcPPU5t50GgqPc1iaMskUIGyR1vNRMpsKcFqjBuB8K /wnpQE+fvBGL8cjZCI4UeNVHj662F1vsaPM3sBTXW6NZDeDAkLEU1bWR50UWifGMxajay rNjhK2mKdmuzt6wlbECCLYM7LgZdw5gJTZlSgLsE4DDr1DcuwP99OVEQGRAyY/4byq9Kc qYGLozs6Dmgm7PIttadP3iHyQB2SC8R2Gg5CY1Hirtc9Fi1wboi77KBczYMwwjEEi9JTv cmmyBpvcI2tSi2k49AYFR2FFpYdmwyrAhnka18NJlW4EqLj1S1nffP42/IrgmEtdNvA== 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=cf0FCJtZ; 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 12261606A32C; Fri, 4 Dec 2026 10:57:38 +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=cf0FCJtZ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 858861F000C2; Fri, 4 Dec 2026 10:57:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381857; bh=yOHQHzS+U8vNbPjJ5K0bx1+6j+C3tTGQNqPyNNgcn1U=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=cf0FCJtZ+9zgSKeRWu+a7QggAtCaMzb25nMVIX/oNzpPxDqQoaPNeF6sGsVelTTx4 QiINBRxnANCoYt/PLOHAhhasmvK2uDkz1J3ML8CKNC/DDx96ShdZbxja4wkY8ePv5f 43KUhS2LsLprBHwVsH/8DnVd/gLCZGnrSl1UvgrE= 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.18 204/703] HID: sensor-hub: Remove clients before stopping hardware Date: Fri, 4 Dec 2026 19:01:43 +0900 Message-ID: <20261204100633.277460496@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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 6.18-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