linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Stein <alexander.stein@ew.tq-group.com>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: Alexander Stein <alexander.stein@ew.tq-group.com>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/1] PCI/sysfs: get rid of pci_sysfs_init late_initcall
Date: Thu, 16 Mar 2023 11:30:36 +0100	[thread overview]
Message-ID: <20230316103036.1837869-1-alexander.stein@ew.tq-group.com> (raw)

All this initcall does is creating sysfs file for devices already
added to the bus. But this is racing with pci_host_probe which will
add sysfs files on it's own merit.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=215515
Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com>
---
This is a different approach to fix the race condition mentioned in the
link. From what I can see is that the functions for creating sysfs are
called during pci bus registration anyway, so there is no need to
iterate once again.

 drivers/pci/pci-sysfs.c | 33 ---------------------------------
 1 file changed, 33 deletions(-)

diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index dd0d9d9bc509..00c8cc3c40ff 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -31,8 +31,6 @@
 #include <linux/aperture.h>
 #include "pci.h"
 
-static int sysfs_initialized;	/* = 0 */
-
 /* show configuration fields */
 #define pci_config_attr(field, format_string)				\
 static ssize_t								\
@@ -953,9 +951,6 @@ void pci_create_legacy_files(struct pci_bus *b)
 {
 	int error;
 
-	if (!sysfs_initialized)
-		return;
-
 	b->legacy_io = kcalloc(2, sizeof(struct bin_attribute),
 			       GFP_ATOMIC);
 	if (!b->legacy_io)
@@ -1494,9 +1489,6 @@ static const struct attribute_group pci_dev_resource_resize_group = {
 
 int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
 {
-	if (!sysfs_initialized)
-		return -EACCES;
-
 	return pci_create_resource_files(pdev);
 }
 
@@ -1508,34 +1500,9 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
  */
 void pci_remove_sysfs_dev_files(struct pci_dev *pdev)
 {
-	if (!sysfs_initialized)
-		return;
-
 	pci_remove_resource_files(pdev);
 }
 
-static int __init pci_sysfs_init(void)
-{
-	struct pci_dev *pdev = NULL;
-	struct pci_bus *pbus = NULL;
-	int retval;
-
-	sysfs_initialized = 1;
-	for_each_pci_dev(pdev) {
-		retval = pci_create_sysfs_dev_files(pdev);
-		if (retval) {
-			pci_dev_put(pdev);
-			return retval;
-		}
-	}
-
-	while ((pbus = pci_find_next_bus(pbus)))
-		pci_create_legacy_files(pbus);
-
-	return 0;
-}
-late_initcall(pci_sysfs_init);
-
 static struct attribute *pci_dev_dev_attrs[] = {
 	&dev_attr_boot_vga.attr,
 	NULL,
-- 
2.34.1


                 reply	other threads:[~2023-03-16 10:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20230316103036.1837869-1-alexander.stein@ew.tq-group.com \
    --to=alexander.stein@ew.tq-group.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 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).