Skip to contentSkip to conversation

EDAC/amd64: replace sprintf with sysfs_emit in show functions

PATCH In review Marcelo Moreira 2 participants 3 messages Jun 29, 2025 – Jul 1, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 EDAC/amd64: replace sprintf with sysfs_emit in show functions

Update all device attribute 'show' callbacks in the EDAC AMD64 driver to utilize sysfs_emit(). This change adheres to the recommendation outlined in Documentation/filesystems/sysfs.rst.

This modification aligns with current sysfs subsystem guidelines.

---
 drivers/edac/amd64_edac.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/edac/amd64_edac.c +5 -5
index b681c0663203..b6d211255ef0 100644
@@ -552,7 +552,7 @@ static ssize_t reg##_show(struct device *dev,				\
 	struct mem_ctl_info *mci = to_mci(dev);				\
 	struct amd64_pvt *pvt = mci->pvt_info;				\
 									\
-	return sprintf(data, "0x%016llx\n", (u64)pvt->reg);		\
+	return  sysfs_emit(data, "0x%016llx\n", (u64)pvt->reg);		\
 }
 
 EDAC_DCT_ATTR_SHOW(dhar);
@@ -571,7 +571,7 @@ static ssize_t dram_hole_show(struct device *dev, struct device_attribute *mattr
 
 	get_dram_hole_info(mci, &hole_base, &hole_offset, &hole_size);
 
-	return sprintf(data, "%llx %llx %llx\n", hole_base, hole_offset,
+	return sysfs_emit(data, "%llx %llx %llx\n", hole_base, hole_offset,
 						 hole_size);
 }
 
@@ -602,7 +602,7 @@ static ssize_t inject_section_show(struct device *dev,
 {
 	struct mem_ctl_info *mci = to_mci(dev);
 	struct amd64_pvt *pvt = mci->pvt_info;
-	return sprintf(buf, "0x%x\n", pvt->injection.section);
+	return sysfs_emit(buf, "0x%x\n", pvt->injection.section);
 }
 
 /*
@@ -638,7 +638,7 @@ static ssize_t inject_word_show(struct device *dev,
 {
 	struct mem_ctl_info *mci = to_mci(dev);
 	struct amd64_pvt *pvt = mci->pvt_info;
-	return sprintf(buf, "0x%x\n", pvt->injection.word);
+	return sysfs_emit(buf, "0x%x\n", pvt->injection.word);
 }
 
 /*
@@ -675,7 +675,7 @@ static ssize_t inject_ecc_vector_show(struct device *dev,
 {
 	struct mem_ctl_info *mci = to_mci(dev);
 	struct amd64_pvt *pvt = mci->pvt_info;
-	return sprintf(buf, "0x%x\n", pvt->injection.bit_map);
+	return sysfs_emit(buf, "0x%x\n", pvt->injection.bit_map);
 }
 
 /*
Signature · 1 line
2.50.0
#1 lore raw
Quoted 16 lines · Marcelo Moreira

Update all device attribute 'show' callbacks in the EDAC AMD64 driver to utilize sysfs_emit(). This change adheres to the recommendation outlined in Documentation/filesystems/sysfs.rst.

This modification aligns with current sysfs subsystem guidelines.

---
 drivers/edac/amd64_edac.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/edac/amd64_edac.c +0 -0
index b681c0663203..b6d211255ef0 100644

drivers/edac/amd64_edac.c static ssize_t reg##_show(struct device *dev, \ · line 555

Quoted 5 lines
drivers/edac/amd64_edac.c +1 -1
@@ -552,7 +552,7 @@ static ssize_t reg##_show(struct device *dev,				\
 	struct mem_ctl_info *mci = to_mci(dev);				\
 	struct amd64_pvt *pvt = mci->pvt_info;				\
 									\
-	return sprintf(data, "0x%016llx\n", (u64)pvt->reg);		\
+	return  sysfs_emit(data, "0x%016llx\n", (u64)pvt->reg);		\

Why the extra ' '?

Quoted 31 lines
drivers/edac/amd64_edac.c +3 -3
 }
 
 EDAC_DCT_ATTR_SHOW(dhar);
@@ -571,7 +571,7 @@ static ssize_t dram_hole_show(struct device *dev, struct device_attribute *mattr
 
 	get_dram_hole_info(mci, &hole_base, &hole_offset, &hole_size);
 
-	return sprintf(data, "%llx %llx %llx\n", hole_base, hole_offset,
+	return sysfs_emit(data, "%llx %llx %llx\n", hole_base, hole_offset,
 						 hole_size);
 }
 
@@ -602,7 +602,7 @@ static ssize_t inject_section_show(struct device *dev,
 {
 	struct mem_ctl_info *mci = to_mci(dev);
 	struct amd64_pvt *pvt = mci->pvt_info;
-	return sprintf(buf, "0x%x\n", pvt->injection.section);
+	return sysfs_emit(buf, "0x%x\n", pvt->injection.section);
 }
 
 /*
@@ -638,7 +638,7 @@ static ssize_t inject_word_show(struct device *dev,
 {
 	struct mem_ctl_info *mci = to_mci(dev);
 	struct amd64_pvt *pvt = mci->pvt_info;
-	return sprintf(buf, "0x%x\n", pvt->injection.word);
+	return sysfs_emit(buf, "0x%x\n", pvt->injection.word);
 }
 
 /*

drivers/edac/amd64_edac.c static ssize_t inject_ecc_vector_show(struct device *dev, · line 678

Quoted 5 lines
drivers/edac/amd64_edac.c +1 -1
@@ -675,7 +675,7 @@ static ssize_t inject_ecc_vector_show(struct device *dev,
 {
 	struct mem_ctl_info *mci = to_mci(dev);
 	struct amd64_pvt *pvt = mci->pvt_info;
-	return sprintf(buf, "0x%x\n", pvt->injection.bit_map);
+	return sysfs_emit(buf, "0x%x\n", pvt->injection.bit_map);

There's nothing wrong with these sprintf() lines, so no need to change them, right?

I only recommend making this type of change when adding new sysfs files, no need for churn on old files when it is not needed at all.

thanks,

greg k-h

#2 lore raw

Em seg., 30 de jun. de 2025 às 02:07, Greg KH
<[email protected]> escreveu:

Quoted 13 lines · Marcelo Moreira
Quoted 11 lines

Update all device attribute 'show' callbacks in the EDAC AMD64 driver to utilize sysfs_emit(). This change adheres to the recommendation outlined in Documentation/filesystems/sysfs.rst.

This modification aligns with current sysfs subsystem guidelines.

---
 drivers/edac/amd64_edac.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Quoted 12 lines

drivers/edac/amd64_edac.c static ssize_t reg##_show(struct device *dev, \ · line 555

Quoted 10 lines
drivers/edac/amd64_edac.c +1 -1
index b681c0663203..b6d211255ef0 100644
@@ -552,7 +552,7 @@ static ssize_t reg##_show(struct device *dev,                             \
      struct mem_ctl_info *mci = to_mci(dev);                         \
      struct amd64_pvt *pvt = mci->pvt_info;                          \
                                                                      \
-     return sprintf(data, "0x%016llx\n", (u64)pvt->reg);             \
+     return  sysfs_emit(data, "0x%016llx\n", (u64)pvt->reg);         \

Why the extra ' '?

I didn't notice, sorry.

Quoted 41 lines
Quoted 32 lines
drivers/edac/amd64_edac.c +3 -3
 }
 
 EDAC_DCT_ATTR_SHOW(dhar);
@@ -571,7 +571,7 @@ static ssize_t dram_hole_show(struct device *dev, struct device_attribute *mattr
 
      get_dram_hole_info(mci, &hole_base, &hole_offset, &hole_size);
 
-     return sprintf(data, "%llx %llx %llx\n", hole_base, hole_offset,
+     return sysfs_emit(data, "%llx %llx %llx\n", hole_base, hole_offset,
                                               hole_size);
 }
 
@@ -602,7 +602,7 @@ static ssize_t inject_section_show(struct device *dev,
 {
      struct mem_ctl_info *mci = to_mci(dev);
      struct amd64_pvt *pvt = mci->pvt_info;
-     return sprintf(buf, "0x%x\n", pvt->injection.section);
+     return sysfs_emit(buf, "0x%x\n", pvt->injection.section);
 }
 
 /*
@@ -638,7 +638,7 @@ static ssize_t inject_word_show(struct device *dev,
 {
      struct mem_ctl_info *mci = to_mci(dev);
      struct amd64_pvt *pvt = mci->pvt_info;
-     return sprintf(buf, "0x%x\n", pvt->injection.word);
+     return sysfs_emit(buf, "0x%x\n", pvt->injection.word);
 }
 
 /*

drivers/edac/amd64_edac.c static ssize_t inject_ecc_vector_show(struct device *dev, · line 678

Quoted 5 lines
drivers/edac/amd64_edac.c +1 -1
@@ -675,7 +675,7 @@ static ssize_t inject_ecc_vector_show(struct device *dev,
 {
      struct mem_ctl_info *mci = to_mci(dev);
      struct amd64_pvt *pvt = mci->pvt_info;
-     return sprintf(buf, "0x%x\n", pvt->injection.bit_map);
+     return sysfs_emit(buf, "0x%x\n", pvt->injection.bit_map);

There's nothing wrong with these sprintf() lines, so no need to change them, right?

Quoted 3 lines

I only recommend making this type of change when adding new sysfs files, no need for churn on old files when it is not needed at all.

Understood Greg, thanks for the feedback :)

--
Cheers,
Marcelo Moreira