[PATCH v2 04/10] PCI/AER: Hide the "aer" sysfs directory when AER is unavailable
From: Yazen Ghannam
Date: Fri Sep 18 2026 - 11:05:07 EST
aer_attr_group is a named group, so sysfs creates an "aer" directory for
every PCI device. aer_attrs_are_visible() hides the attributes when the
device has no aer_info, but internal_create_group() only skips the
directory when is_visible() returns SYSFS_GROUP_INVISIBLE for the first
attribute. The result is an empty /sys/bus/pci/devices/*/aer/ on every
device without AER.
Switch to DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(), which returns
SYSFS_GROUP_INVISIBLE when the group predicate is false. Drop the
per-attribute callback, since all four attributes share one condition.
aer_stats_attr_group is unnamed and creates no directory, so it is left
alone.
Fixes: b4fe7398def6 ("PCI/AER: Add sysfs attributes for log ratelimits")
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Closes: https://lore.kernel.org/linux-pci/20260714191826.BA81E1F000E9@xxxxxxxxxxxxxxx/
Assisted-by: LLM
Signed-off-by: Yazen Ghannam <yazen.ghannam@xxxxxxx>
---
drivers/pci/pcie/aer.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c
index 5498fc605556..91d73bd2ca7c 100644
--- a/drivers/pci/pcie/aer.c
+++ b/drivers/pci/pcie/aer.c
@@ -777,22 +777,19 @@ static struct attribute *aer_attrs[] = {
NULL
};
-static umode_t aer_attrs_are_visible(struct kobject *kobj,
- struct attribute *a, int n)
+static bool aer_group_visible(struct kobject *kobj)
{
- struct device *dev = kobj_to_dev(kobj);
- struct pci_dev *pdev = to_pci_dev(dev);
+ struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
- if (!pdev->aer_info)
- return 0;
-
- return a->mode;
+ return !!pdev->aer_info;
}
+DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(aer);
+
const struct attribute_group aer_attr_group = {
.name = "aer",
.attrs = aer_attrs,
- .is_visible = aer_attrs_are_visible,
+ .is_visible = SYSFS_GROUP_VISIBLE(aer),
};
static void pci_dev_aer_stats_incr(struct pci_dev *pdev,
--
2.43.0