Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: bhelgaas@google.com, rafael@kernel.org
Cc: Alex Williamson <alex.williamson@redhat.com>,
	linux-pci@vger.kernel.org, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] PCI: Increment PM usage counter when probing reset methods
Date: Tue, 22 Apr 2025 17:05:32 -0600	[thread overview]
Message-ID: <20250422230534.2295291-3-alex.williamson@redhat.com> (raw)
In-Reply-To: <20250422230534.2295291-1-alex.williamson@redhat.com>

We can get different results probing reset methods for a device
depending on its power state.  For example, reading the PM control
register of a device in D3cold will always indicate NoSoftRst+,
preventing us from correctly probing PM reset support.

Increment the PM usage counter before any probes and use the cleanup
__free facility to automatically drop the usage counter out of scope.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
 drivers/pci/pci-sysfs.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index c6cda56ca52c..71a36f57ef57 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -1475,6 +1475,9 @@ static ssize_t reset_method_store(struct device *dev,
 		return count;
 	}
 
+	pm_runtime_get_sync(dev);
+	struct device *pmdev __free(pm_runtime_put) = dev;
+
 	if (sysfs_streq(buf, "default")) {
 		pci_init_reset_methods(pdev);
 		return count;
-- 
2.48.1


  parent reply	other threads:[~2025-04-22 23:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-22 23:05 [PATCH 0/2] PCI/PM: Elevate PM usage during reset probing Alex Williamson
2025-04-22 23:05 ` [PATCH 1/2] PM: runtime: Define pm_runtime_put cleanup helper Alex Williamson
2025-04-23 12:21   ` Rafael J. Wysocki
2025-04-22 23:05 ` Alex Williamson [this message]
2025-04-23 21:10 ` [PATCH 0/2] PCI/PM: Elevate PM usage during reset probing 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=20250422230534.2295291-3-alex.williamson@redhat.com \
    --to=alex.williamson@redhat.com \
    --cc=bhelgaas@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@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