Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1128233rwb; Thu, 6 Oct 2022 08:47:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5m1r+j+Y13OtwUpO+nHNW/GZEchhWNhdNPhCJQufN1Z2fs3nABn1IV2pX6ypawfak9cR+O X-Received: by 2002:a17:907:72d3:b0:78d:2153:648a with SMTP id du19-20020a17090772d300b0078d2153648amr375240ejc.513.1665071224675; Thu, 06 Oct 2022 08:47:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665071224; cv=none; d=google.com; s=arc-20160816; b=Gf7j4ocZmQAFH6GfgfO3G4Z+Yn+iTkWm7bqctwtppKIHQZ+r1YO098ITDhTq7bUemq lvzE6QlO90aK9/Lc5GK6Bl7V21DOdt1UBupXNiXwIWpnSl2hdQebUipZSiEc2jwKHGyV yQxZ865A298/r64diefZebRuuHbZshJ4m/c+12xkw5KMCeeVwJdV1M0VuKZqyqF/jg+m /frk4elejOGqvBhT9Hn69hz0oaSHs3IDvGXwcXlLTZv28e1EXd3yGb7+gRUJ8HC31ALQ 94rhYbvO6dYCpwf89547XPSR9s7T5vEOxPd6NrJRnHeRfBFoxepRqMoIr/5I7MSCV9yE Vx+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=zmNd1zKQhgK/w8oZWKl6OH2Lm8UT7aeBSqQ/QOx7D40=; b=ywkuYMD1Wsbq64GXIPxaLknOpjVLEZZ82NPMmR8yh+jTpsGWTJjaYKayzMJpoChZqH wAvMCKeFPKgYvE0os+9ya0TonDjlw1dR7qRnUSFMYVfdsvb9CSBYPD6vPBu5Bo5HAUeS 18tYB65YMGms9yeoCvf3LGMPkKTYEyxF2UWwqfsnUiqztk5RR5sxCY/gc7BuzunHq4SJ hFt41a+R+0w5TQ5wHtDYz60rZBS70BPi6QiWsDRunK0apur+ZwLwSXmoipWCUGsa7cr3 /ri280wAQ6NjzzhP+nnkhtPmIWyrWsW6khoe7ftamRyODvL3YxgZIu3UMgnQBag5Hawk MXiQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k2-20020a170906680200b00783e7d72fc0si13819142ejr.272.2022.10.06.08.46.34; Thu, 06 Oct 2022 08:47:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231356AbiJFPkA (ORCPT + 99 others); Thu, 6 Oct 2022 11:40:00 -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: 8bit X-Ovh-Tracer-Id: 14079941288775550566 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvfedrfeeihedggeejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgggfestdekredtredttdenucfhrhhomhepufhtvghphhgvnhcumfhithhtuceoshhtvghvvgesshhkvddrohhrgheqnecuggftrfgrthhtvghrnhepudevveffvdfgledvgfekveefvedvheeuuedvgeejudfggeeuhffgvddtieevvdeinecuffhomhgrihhnpehsthgrtghkvgigtghhrghnghgvrdgtohhmnecukfhppedtrddtrddtrddtpdekvddrieehrddvhedrvddtudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphhouhhtpdhhvghlohepphhlrgihvghrjedugedrhhgrrdhovhhhrdhnvghtpdhinhgvtheptddrtddrtddrtddpmhgrihhlfhhrohhmpehsthgvvhgvsehskhdvrdhorhhgpdhnsggprhgtphhtthhopedupdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdfovfetjfhoshhtpehmohehkeef X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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=off (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 pci_dev *pdev) void pcie_aspm_init_link_state(struct pci_dev *pdev) { struct pcie_link_state *link; - int blacklist = !!pcie_aspm_sanity_check(pdev); + int blacklist; 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 = !!pcie_aspm_sanity_check(pdev); pcie_aspm_cap_init(link, blacklist); /* Setup initial Clock PM state */ base-commit: 833477fce7a14d43ae4c07f8ddc32fa5119471a2 -- 2.30.2