public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/1] Guard pci_create_sysfs_dev_files with atomic value
@ 2023-03-16  9:15 Alexander Stein
  2023-03-16  9:18 ` Alexander Stein
  2023-03-16  9:23 ` Oliver Neukum
  0 siblings, 2 replies; 11+ messages in thread
From: Alexander Stein @ 2023-03-16  9:15 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Korneliusz Osmenda, linux-pci, linux-kernel, Alexander Stein

From: Korneliusz Osmenda <korneliuszo@gmail.com>

On Gateworks Ventana there is a number of PCI devices and:
  - imx6_pcie_probe takes longer than start of late init
  - pci_sysfs_init sets up flag sysfs_initialized
  - pci_sysfs_init initializes already found devices
  - imx6_pcie_probe tries to reinitialize device

Link: https://bugzilla.kernel.org/show_bug.cgi?id=215515

Signed-off-by: Korneliusz Osmenda <korneliuszo@gmail.com>
Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com>
---
 drivers/pci/pci-sysfs.c | 6 ++++++
 include/linux/pci.h     | 2 ++
 2 files changed, 8 insertions(+)

diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index dd0d9d9bc509..998e44716b6f 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -1497,6 +1497,9 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
 	if (!sysfs_initialized)
 		return -EACCES;
 
+	if (atomic_cmpxchg(&pdev->sysfs_init_cnt, 0, 1) == 1)
+		return 0;		/* already added */
+
 	return pci_create_resource_files(pdev);
 }
 
@@ -1511,6 +1514,9 @@ void pci_remove_sysfs_dev_files(struct pci_dev *pdev)
 	if (!sysfs_initialized)
 		return;
 
+	if (atomic_cmpxchg(&pdev->sysfs_init_cnt, 1, 0) == 0)
+		return;		/* already removed */
+
 	pci_remove_resource_files(pdev);
 }
 
diff --git a/include/linux/pci.h b/include/linux/pci.h
index b50e5c79f7e3..024313a7a90a 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -467,6 +467,8 @@ struct pci_dev {
 	pci_dev_flags_t dev_flags;
 	atomic_t	enable_cnt;	/* pci_enable_device has been called */
 
+	atomic_t	sysfs_init_cnt;	/* pci_create_sysfs_dev_files has been called */
+
 	u32		saved_config_space[16]; /* Config space saved at suspend time */
 	struct hlist_head saved_cap_space;
 	int		rom_attr_enabled;	/* Display of ROM attribute enabled? */
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-03-21  9:10 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-16  9:15 [PATCH v2 1/1] Guard pci_create_sysfs_dev_files with atomic value Alexander Stein
2023-03-16  9:18 ` Alexander Stein
2023-03-16  9:23 ` Oliver Neukum
2023-03-16  9:33   ` Alexander Stein
2023-03-16 11:17     ` Oliver Neukum
2023-03-16 11:58       ` Alexander Stein
2023-03-16 12:23         ` Oliver Neukum
2023-03-16 13:16           ` Alexander Stein
2023-03-16 14:01             ` Oliver Neukum
2023-03-16 15:00               ` Alexander Stein
2023-03-21  9:09               ` Oliver Neukum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox