diff mbox series

[RFC,3/6] memory: scrub: Add function to show scrub attributes in decimal

Message ID 20231114125648.1146-4-shiju.jose@huawei.com
State Superseded
Headers show
Series cxl: Add support for CXL feature commands, CXL device patrol scrub control and DDR5 ECS control features | expand

Commit Message

Shiju Jose Nov. 14, 2023, 12:56 p.m. UTC
From: Shiju Jose <shiju.jose@huawei.com>

Add function to show scrub control attributes to the user
in decimal.

Signed-off-by: Shiju Jose <shiju.jose@huawei.com>
---
 drivers/memory/scrub/memory-scrub.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/memory/scrub/memory-scrub.c b/drivers/memory/scrub/memory-scrub.c
index b3011e7cd062..ff5b4a52d2da 100755
--- a/drivers/memory/scrub/memory-scrub.c
+++ b/drivers/memory/scrub/memory-scrub.c
@@ -130,6 +130,20 @@  static ssize_t scrub_attr_show(struct device *dev,
 	u64 val;
 	struct scrub_device_attribute *hattr = to_scrub_attr(devattr);
 
+	ret = hattr->ops->read(dev, hattr->attr, hattr->region_id, &val);
+	if (ret < 0)
+		return ret;
+
+	return sprintf(buf, "%lld\n", val);
+}
+
+static ssize_t scrub_attr_show_hex(struct device *dev,
+				   struct device_attribute *devattr, char *buf)
+{
+	int ret;
+	u64 val;
+	struct scrub_device_attribute *hattr = to_scrub_attr(devattr);
+
 	ret = hattr->ops->read(dev, hattr->attr, hattr->region_id, &val);
 	if (ret < 0)
 		return ret;
@@ -236,8 +250,12 @@  static struct attribute *scrub_genattr(const void *drvdata,
 	hattr->region_id = region_id;
 
 	dattr = &hattr->dev_attr;
-	dattr->show = is_string ? scrub_attr_show_string : scrub_attr_show;
-	dattr->store = is_hex ? scrub_attr_store_hex : scrub_attr_store;
+	if (is_string) {
+		dattr->show = scrub_attr_show_string;
+	} else {
+		dattr->show = is_hex ? scrub_attr_show_hex : scrub_attr_show;
+		dattr->store = is_hex ? scrub_attr_store_hex : scrub_attr_store;
+	}
 
 	a = &dattr->attr;
 	sysfs_attr_init(a);