[PATCH] PCIE: create sysfs directory on first use

From: Randy.Dunlap
Date: Fri Jul 07 2006 - 19:48:15 EST


From: Randy Dunlap <rdunlap@xxxxxxxxxxxx>

Dave Jones had a question about why /sys/bus/pci_express/devices
shows up even when there are no PCI-Express devices in a system
(if the config option is enabled).
Greg KH said that it could be added on its first use.

This patch creates that directory only when a device is discovered
and added to the directory. On my ancient P-III test system,
the directory is never added, but on my Dell D610 notebook and
other dual-core system, it is added during boot discovery.

Does the "drivers" directory need some special handling also?

Signed-off-by: Randy Dunlap <rdunlap@xxxxxxxxxxxx>
---
drivers/pci/pcie/portdrv_core.c | 11 ++++++++++-
drivers/pci/pcie/portdrv_pci.c | 1 -
2 files changed, 10 insertions(+), 2 deletions(-)

--- linux-2618-rc1.orig/drivers/pci/pcie/portdrv_core.c
+++ linux-2618-rc1/drivers/pci/pcie/portdrv_core.c
@@ -274,6 +274,8 @@ int pcie_port_device_probe(struct pci_de
return -ENODEV;
}

+static int pcie_dev_registered; /* register on first use */
+
int pcie_port_device_register(struct pci_dev *dev)
{
struct pcie_port_device_ext *p_ext;
@@ -303,6 +305,9 @@ int pcie_port_device_register(struct pci
struct pcie_device *child;

if (capabilities & (1 << i)) {
+ if (!pcie_dev_registered)
+ pcie_port_bus_register();
+
child = alloc_pcie_device(
dev, /* parent */
type, /* port type */
@@ -405,11 +410,15 @@ void pcie_port_device_remove(struct pci_
void pcie_port_bus_register(void)
{
bus_register(&pcie_port_bus_type);
+ pcie_dev_registered = 1;
}

void pcie_port_bus_unregister(void)
{
- bus_unregister(&pcie_port_bus_type);
+ if (pcie_dev_registered) {
+ bus_unregister(&pcie_port_bus_type);
+ pcie_dev_registered = 0;
+ }
}

int pcie_port_service_register(struct pcie_port_service_driver *new)
--- linux-2618-rc1.orig/drivers/pci/pcie/portdrv_pci.c
+++ linux-2618-rc1/drivers/pci/pcie/portdrv_pci.c
@@ -129,7 +129,6 @@ static int __init pcie_portdrv_init(void
{
int retval = 0;

- pcie_port_bus_register();
retval = pci_register_driver(&pcie_portdrv);
if (retval)
pcie_port_bus_unregister();


---
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/