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=1796387846; b=y2/t8aBsZJFCocbFUDTwpsm+s+BV8dVPqvbs8XXm4jwpMrR0N532mrnF7rnv9MfhptJx 4STozlIAmRelrZGXOXuUFPTiXZn2YUjTcBPdjmTF7iB7fjRrkNMTsWHlPwGkh557AajLG /KdV/V6K0hBvyZDl1ZDE+dP/k1dgzgG8WOMHVB5pezcKUNNUok+ssCJwdfCdW79nTxZdx T703NUrQYrnzvgnxN2O8JHWLl5bx0SwYGKegdjoOgkL8FAQO/nhJovnWNOYBGFe578UvQ kVCEfTx4KK+cS9Rv6DnTmkIno7k9FpLvjohbeQRDNP1Rm1MGmaTeR6UMvqdD1ZjLTvg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387846; 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-Type:Content-Transfer-Encoding; bh=ZPZ9raAbGiRGiMSJ7yp0d/SPajL5tWiwq9irnf76Kw0=; b=QS/mc9utD04an9teDhtKYdFvpCdouEmSmAfAx9n+npmTtylh89rGHLL5fUWf6g7DecfX xEoLJau+qnrc6TICMOQGXumDaFJWd1YxOyP1UHCP/nVpzHJm63GAlG4VAf1vLYwwGtDcT 89B5/OmEcN09MlLvbTpmU12hHK9rR4ODbOh6G3utL8oRf/oU1aCTlYZ8mvnKeqOn6X7/Y sjo6PlDHrK89Raw/kOOJbyjjj7s8AFsQw0ECc0DwzmmVW26KGozumZkxRHWsRRZhHRlVF aD8YSV4/pshhTXeRODpxTDGQK3LBZaKdlwH074v+Q0+BqgZ83iBPL3HAyzg450lrt3g== 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=lnmKND2W; 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 78410606A32F; Fri, 4 Dec 2026 12:37:26 +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=lnmKND2W Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB2921F00936; Fri, 4 Dec 2026 12:37:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387846; bh=ZPZ9raAbGiRGiMSJ7yp0d/SPajL5tWiwq9irnf76Kw0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lnmKND2WUlDLsGJXUPZU425MT1omgOQ6b42JywrJkgeoQklHDvAYnNWJV0rFMo0Gt rzLUm4zu9myt6ydF3q2rapNoXdzMZMRsp9k4955cPH+dxC63u5hnyxehsphFsrCQwy GIBViWIDfqUpfJLZDnqxHcx/8s+x88po8vu154hk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shyam Sundar S K , "Mario Limonciello (AMD)" , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Sasha Levin Subject: [PATCH 6.1 0382/1059] platform/x86/amd/pmc: clear devm-managed pointers on remove to prevent stale reuse Date: Fri, 4 Dec 2026 18:58:33 +0900 Message-ID: <20261204100654.189727988@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: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Shyam Sundar S K [ Upstream commit c9ba86f5411730ebd333d94b9e1aa8f652dc743f ] The driver stores its state in a single file-scope static struct amd_pmc_dev, which is reused on every bind. Its regbase, smu_virt_addr, stb_virt_addr and fch_virt_addr members are MMIO mappings created with devm_ioremap(). On unbind the driver core unmaps these mappings, but it does not clear the pointers in the static struct. Since the struct is not freed, the members keep pointing at the now-unmapped addresses. On the next bind, the probe path re-maps a region only when its pointer is still NULL, so the stale pointer is reused and the following memcpy_fromio()/ioread32() touches freed MMIO, causing use-after-unmap crash. Clear these pointers in amd_pmc_remove() so the next probe re-maps them instead of reusing stale ones. Signed-off-by: Shyam Sundar S K Reviewed-by: Mario Limonciello (AMD) Fixes: 156ec4731cb22b ("platform/x86: amd-pmc: Add AMD platform support for S2Idle") Link: https://patch.msgid.link/20260929155609.1712638-1-Shyam-sundar.S-k@amd.com Reviewed-by: Ilpo Järvinen Signed-off-by: Ilpo Järvinen [ sashal: Added four NULL assignments in amd_pmc_remove() after mutex_destroy(), since the function returns int and lacks the upstream deinit call used as context. ] Signed-off-by: Sasha Levin --- drivers/platform/x86/amd/pmc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/platform/x86/amd/pmc.c b/drivers/platform/x86/amd/pmc.c index ca3b874058ff0..9df5f7eb66115 100644 --- a/drivers/platform/x86/amd/pmc.c +++ b/drivers/platform/x86/amd/pmc.c @@ -1024,6 +1024,10 @@ static int amd_pmc_remove(struct platform_device *pdev) amd_pmc_dbgfs_unregister(dev); pci_dev_put(dev->rdev); mutex_destroy(&dev->lock); + dev->regbase = NULL; + dev->smu_virt_addr = NULL; + dev->stb_virt_addr = NULL; + dev->fch_virt_addr = NULL; return 0; } -- 2.53.0