[PATCH v6 3/3] PCI/DOE: Only expose the sysfs attribute group if DOE is supported

From: Alistair Francis
Date: Thu Aug 17 2023 - 19:59:35 EST


Now that the new attr_is_visible() function is avaliable as part of
`struct attribute_group` we can use that to hide the attribute group
on devices that don't support DOE.

Signed-off-by: Alistair Francis <alistair.francis@xxxxxxx>
---
v6:
- Add patch

drivers/pci/doe.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/doe.c b/drivers/pci/doe.c
index 316aac60ccd5..1a021e8b3e0c 100644
--- a/drivers/pci/doe.c
+++ b/drivers/pci/doe.c
@@ -95,8 +95,7 @@ struct pci_doe_task {
};

#ifdef CONFIG_SYSFS
-static umode_t pci_doe_sysfs_attr_is_visible(struct kobject *kobj,
- struct attribute *a, int n)
+static umode_t pci_doe_sysfs_group_is_visible(struct kobject *kobj)
{
struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
unsigned long total_features = 0;
@@ -112,7 +111,17 @@ static umode_t pci_doe_sysfs_attr_is_visible(struct kobject *kobj,
if (total_features == 0)
return 0;

- return a->mode;
+ return S_IRWXU | S_IRUGO | S_IXUGO;
+}
+
+static umode_t pci_doe_sysfs_attr_is_visible(struct kobject *kobj,
+ struct attribute *a, int n)
+{
+ if (pci_doe_sysfs_group_is_visible(kobj)) {
+ return a->mode;
+ }
+
+ return 0;
}

static struct attribute *pci_dev_doe_feature_attrs[] = {
@@ -122,6 +131,7 @@ static struct attribute *pci_dev_doe_feature_attrs[] = {
const struct attribute_group pci_dev_doe_feature_group = {
.name = "doe_features",
.attrs = pci_dev_doe_feature_attrs,
+ .attr_is_visible = pci_doe_sysfs_group_is_visible,
.is_visible = pci_doe_sysfs_attr_is_visible,
};

--
2.41.0