diff mbox series

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

Message ID 20230817235810.596458-3-alistair.francis@wdc.com
State New
Headers show
Series [v6,1/3] PCI/DOE: Expose the DOE features via sysfs | expand

Commit Message

Alistair Francis Aug. 17, 2023, 11:58 p.m. UTC
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@wdc.com>
---
v6:
 - Add patch

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

Patch

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,
 };