[PATCH V1 3/4] PCI/sysfs: Take the device lock when setting reset methods

From: Vidya Sagar

Date: Thu Nov 19 2026 - 05:07:48 EST


reset_method_store() updates dev->reset_methods without holding any
lock. A reset can run at the same time: __pci_reset_function_locked()
walks the list one entry at a time while the write copies the new list
over it, so the reset may use a mix of the old and the new list.

Take the device lock in reset_method_store(), as
__pci_reset_function_locked() already requires. This also serializes
concurrent writes. The reset methods already run under this lock during
a reset, and probing a method does less than running it, so probing them
with the lock held is safe. A write now waits while a reset of the
device is in progress.

Signed-off-by: Vidya Sagar <vidyas@xxxxxxxxxx>
---
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 6669e9ad5bd3..dff3c2d9408c 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -1643,6 +1643,9 @@ static ssize_t reset_method_store(struct device *dev,
int m, n;
u8 reset_methods[PCI_NUM_RESET_METHODS] = {};

+ /* Serialize against resets and other updates of the list */
+ guard(device)(dev);
+
if (sysfs_streq(buf, "")) {
pdev->reset_methods[0] = 0;
pci_warn(pdev, "All device reset methods disabled by user");
--
2.43.0