From nobody Mon Apr 6 21:11:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4594C433F5 for ; Thu, 6 Oct 2022 15:40:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231329AbiJFPkE (ORCPT ); Thu, 6 Oct 2022 11:40:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231540AbiJFPj5 (ORCPT ); Thu, 6 Oct 2022 11:39:57 -0400 X-Greylist: delayed 4196 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 06 Oct 2022 08:39:53 PDT Received: from 4.mo583.mail-out.ovh.net (4.mo583.mail-out.ovh.net [178.33.111.247]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5435A14D15 for ; Thu, 6 Oct 2022 08:39:52 -0700 (PDT) Received: from player714.ha.ovh.net (unknown [10.108.20.216]) by mo583.mail-out.ovh.net (Postfix) with ESMTP id 8E97023A9C for ; Thu, 6 Oct 2022 12:00:38 +0000 (UTC) Received: from sk2.org (82-65-25-201.subs.proxad.net [82.65.25.201]) (Authenticated sender: steve@sk2.org) by player714.ha.ovh.net (Postfix) with ESMTPSA id 3C67B2F572EBE; Thu, 6 Oct 2022 12:00:35 +0000 (UTC) Authentication-Results: garm.ovh; auth=pass (GARM-102R004facaee04-fba3-4d9d-bada-ccf9502b03c9, 1B208DD073E4D188871243D3B3D058A636382E4D) smtp.auth=steve@sk2.org X-OVh-ClientIp: 82.65.25.201 From: Stephen Kitt To: linux-kernel@vger.kernel.org Cc: Stephen Kitt , Bjorn Helgaas , linux-pci@vger.kernel.org Subject: [PATCH] PCI/ASPM: Call pcie_aspm_sanity_check() as late as possible Date: Thu, 6 Oct 2022 13:59:50 +0200 Message-Id: <20221006115950.821736-1-steve@sk2.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 14079941288775550566 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvfedrfeeihedggeejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgggfestdekredtredttdenucfhrhhomhepufhtvghphhgvnhcumfhithhtuceoshhtvghvvgesshhkvddrohhrgheqnecuggftrfgrthhtvghrnhepudevveffvdfgledvgfekveefvedvheeuuedvgeejudfggeeuhffgvddtieevvdeinecuffhomhgrihhnpehsthgrtghkvgigtghhrghnghgvrdgtohhmnecukfhppedtrddtrddtrddtpdekvddrieehrddvhedrvddtudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphhouhhtpdhhvghlohepphhlrgihvghrjedugedrhhgrrdhovhhhrdhnvghtpdhinhgvtheptddrtddrtddrtddpmhgrihhlfhhrohhmpehsthgvvhgvsehskhdvrdhorhhgpdhnsggprhgtphhtthhopedupdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdfovfetjfhoshhtpehmohehkeef Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In pcie_aspm_init_link_state(), a number of checks are made to determine whether the function should proceed, before the result of the call to pcie_aspm_sanity_check() is actually used. The latter function doesn't change any state, it only reports a result, so calling it later doesn't make any difference to the state of the devices or the information we have about them. But having the call early reportedly can cause null-pointer dereferences; see https://unix.stackexchange.com/q/322337 for one example with pcie_aspm=3Doff (this was reported in 2016, but the relevant code hasn't changed since then). This moves the call to pcie_aspm_sanity_check() just before the result is actually used, giving all the other checks a chance to run first. Signed-off-by: Stephen Kitt --- drivers/pci/pcie/aspm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index a8aec190986c..38df439568b7 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -889,7 +889,7 @@ static void pcie_aspm_update_sysfs_visibility(struct pc= i_dev *pdev) void pcie_aspm_init_link_state(struct pci_dev *pdev) { struct pcie_link_state *link; - int blacklist =3D !!pcie_aspm_sanity_check(pdev); + int blacklist; =20 if (!aspm_support_enabled) return; @@ -923,6 +923,7 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev) * upstream links also because capable state of them can be * update through pcie_aspm_cap_init(). */ + blacklist =3D !!pcie_aspm_sanity_check(pdev); pcie_aspm_cap_init(link, blacklist); =20 /* Setup initial Clock PM state */ base-commit: 833477fce7a14d43ae4c07f8ddc32fa5119471a2 --=20 2.30.2