[H/I/OEM-5.10/OEM-5.13/OEM-5.14] [PATCH 2/4] nvme-pci: cmb sysfs: one file, one value

Kai-Heng Feng kai.heng.feng at canonical.com
Sat Nov 6 12:10:56 UTC 2021


From: Keith Busch <kbusch at kernel.org>

BugLink: https://bugs.launchpad.net/bugs/1950042

An attribute should only be exporting one value as recommended in
Documentation/filesystems/sysfs.rst. Implement CMB attributes this way.
The old attribute will remain for backward compatibility.

Signed-off-by: Keith Busch <kbusch at kernel.org>
Signed-off-by: Christoph Hellwig <hch at lst.de>
(cherry picked from commit 1751e97aa940656b5de0e620f02cf193a275e014)
Signed-off-by: Kai-Heng Feng <kai.heng.feng at canonical.com>
---
 drivers/nvme/host/pci.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 724be85141b75..3d734e60f2146 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -2067,6 +2067,24 @@ static ssize_t cmb_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(cmb);
 
+static ssize_t cmbloc_show(struct device *dev, struct device_attribute *attr,
+		char *buf)
+{
+	struct nvme_dev *ndev = to_nvme_dev(dev_get_drvdata(dev));
+
+	return sysfs_emit(buf, "%u\n", ndev->cmbloc);
+}
+static DEVICE_ATTR_RO(cmbloc);
+
+static ssize_t cmbsz_show(struct device *dev, struct device_attribute *attr,
+		char *buf)
+{
+	struct nvme_dev *ndev = to_nvme_dev(dev_get_drvdata(dev));
+
+	return sysfs_emit(buf, "%u\n", ndev->cmbsz);
+}
+static DEVICE_ATTR_RO(cmbsz);
+
 static umode_t nvme_pci_attrs_are_visible(struct kobject *kobj,
 		struct attribute *a, int n)
 {
@@ -2074,13 +2092,19 @@ static umode_t nvme_pci_attrs_are_visible(struct kobject *kobj,
 		dev_get_drvdata(container_of(kobj, struct device, kobj));
 	struct nvme_dev *dev = to_nvme_dev(ctrl);
 
-	if (a == &dev_attr_cmb.attr && !dev->cmbsz)
-		return 0;
+	if (a == &dev_attr_cmb.attr ||
+	    a == &dev_attr_cmbloc.attr ||
+	    a == &dev_attr_cmbsz.attr) {
+	    	if (!dev->cmbsz)
+			return 0;
+	}
 	return a->mode;
 }
 
 static struct attribute *nvme_pci_attrs[] = {
 	&dev_attr_cmb.attr,
+	&dev_attr_cmbloc.attr,
+	&dev_attr_cmbsz.attr,
 	NULL,
 };
 
-- 
2.32.0




More information about the kernel-team mailing list