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=1796388992; b=zveQWnz/pFzxFqScnW85STKHxWdNghkxOHQUgVnQM9k7XebKxZhFbp+cqZ+4et1iWeGm kNc9pCv0FgnjN4dB3LggLcCikh30PTypx0GCJh7aHzH7OF9fWGFZwDZnYRNNTWRFq/9hZ sotnrb/Re1d5cw2VG+NTpNWixKPmafhkwYXgfewodOGVINTiB/m9sCJp4w99YZYQBMpPW JjxHEfSL1Ewry+TcE0s3st8sClgTZdx/jaNDW9w3quFF9BV0Pas0T3vUyeuzI21BGu4w2 bDYZx1wgpAdYZPyCSEQvtglrwRvF2QCE+Ec7pEiy8q2bGpp8D3qklU6C2X4JTYYMsHQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388992; 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=0ccWl/65spIBq8pKMAS787KU2uJigePSzFcXHmyg9dg=; b=AO1/RpzXiUKSK/8KRFYE0NDnqYoqaXGXE4LAf4uk2TX3zFRchx33KFN592Ttiyi2T57y bOnCiDxILH0+pzLgglOhtzjD6lyoHQmY2lgF+mQmjh0YJlE3pVuetY94KvNNkuhsXXmbv GxtmSFKzZZssNAlo6Mw5AU+GSFUJ5xuKLRHmv/7u6fVQGgM7HqDq3sqB63V27ebCzmF81 TpfzYvzto8F/Sc/3Jh03d4GI5uqFf0mM5nGexe7rOn7TJjYdPEhVcKYx+cqFImq2DPzvl +zMMjVmHZEPakslDsbuP+kjciGTT9QEoRRunz00OdoiHE46PeT73eUMBOUKXU9BaBxQ== 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=oqRaWOf2; 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 1AA05606A322; Fri, 4 Dec 2026 12:56:32 +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=oqRaWOf2 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 226BE1F00934; Fri, 4 Dec 2026 12:56:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388991; bh=0ccWl/65spIBq8pKMAS787KU2uJigePSzFcXHmyg9dg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=oqRaWOf287f6Q7N6gUOljDSfdncojfRJeGVHYK3nJ7sybsHoHTf640mjdj1sxbGR1 MRvl0IgVJ29KrKJnVQ1IhppBtVuQdgRVmAN3mglNykmJz+NQUeERD3YPfdXgLDIjZK EOJt/oUApq4vapoI8gspLa2fQuwApTwTBW2b9HFE= 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.1 0826/1059] HID: sensor-hub: Remove clients before stopping hardware Date: Fri, 4 Dec 2026 19:05:57 +0900 Message-ID: <20261204100705.417737472@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@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.1-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 764e0d16cec52..20ac9df3a1250 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