diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index d15c881e2e7e..8f845b8ad2c7 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1338,6 +1338,11 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev) if (!sysfs_initialized) return -EACCES; +#ifdef CONFIG_NO_GKI + if (atomic_cmpxchg(&pdev->sysfs_init_cnt, 0, 1) == 1) + return 0; /* already added */ +#endif + if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) retval = sysfs_create_bin_file(&pdev->dev.kobj, &pcie_config_attr); else @@ -1417,6 +1422,11 @@ void pci_remove_sysfs_dev_files(struct pci_dev *pdev) if (!sysfs_initialized) return; +#ifdef CONFIG_NO_GKI + if (atomic_cmpxchg(&pdev->sysfs_init_cnt, 1, 0) == 0) + return; /* already removed */ +#endif + pci_remove_capabilities_sysfs(pdev); if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) diff --git a/include/linux/pci.h b/include/linux/pci.h index 9d9c198be7d0..95fd50c28e18 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -453,6 +453,9 @@ struct pci_dev { pci_dev_flags_t dev_flags; atomic_t enable_cnt; /* pci_enable_device has been called */ +#ifdef CONFIG_NO_GKI + atomic_t sysfs_init_cnt; /* pci_create_sysfs_dev_files has been called */ +#endif u32 saved_config_space[16]; /* Config space saved at suspend time */ struct hlist_head saved_cap_space; struct bin_attribute *rom_attr; /* Attribute descriptor for sysfs ROM entry */