From: Stephen Kitt <steve@sk2.org>
To: linux-kernel@vger.kernel.org
Cc: Stephen Kitt <steve@sk2.org>, Bjorn Helgaas <bhelgaas@google.com>,
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 [thread overview]
Message-ID: <20221006115950.821736-1-steve@sk2.org> (raw)
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 <steve@sk2.org>
---
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
next reply other threads:[~2022-10-06 16:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-06 11:59 Stephen Kitt [this message]
2022-12-07 21:56 ` [PATCH] PCI/ASPM: Call pcie_aspm_sanity_check() as late as possible Bjorn Helgaas
2022-12-08 8:00 ` Stephen Kitt
2022-12-08 16:55 ` Bjorn Helgaas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221006115950.821736-1-steve@sk2.org \
--to=steve@sk2.org \
--cc=bhelgaas@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).