All of lore.kernel.org
 help / color / mirror / Atom feed
From: Korneliusz Osmenda <korneliuszo@gmail.com>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] Guard pci_create_sysfs_dev_files with atomic value
Date: Mon, 29 Aug 2022 21:14:43 +0200	[thread overview]
Message-ID: <4469eba2-188b-aab7-07d1-5c77313fc42f@gmail.com> (raw)

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

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

Signed-off-by: Korneliusz Osmenda <korneliuszo@gmail.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 fc804e08e3cb..a6648239e235 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -1378,6 +1378,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);
  }

@@ -1392,6 +1395,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 060af91bafcd..5477de2ef057 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -465,6 +465,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.36.1

             reply	other threads:[~2022-08-29 19:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-29 19:14 Korneliusz Osmenda [this message]
2022-10-06 10:08 ` [PATCH] Guard pci_create_sysfs_dev_files with atomic value Alexander Stein

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=4469eba2-188b-aab7-07d1-5c77313fc42f@gmail.com \
    --to=korneliuszo@gmail.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.