Skip to contentSkip to conversation

fpga: bridge: Use str_enabled_disabled helper in state_show

PATCH RESEND In review Thorsten Blum 3 participants 3 messages Feb 24 – Mar 2 FPGA manager framework

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 fpga: bridge: Use str_enabled_disabled helper in state_show

Replace hard-coded strings with the str_enabled_disabled() helper. This unifies the output and helps the linker with deduplication, which can result in a smaller binary.

---
 drivers/fpga/fpga-bridge.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/fpga/fpga-bridge.c +2 -1
index ca68c38aa4a1..e8ff3e3bf2fc 100644
@@ -12,6 +12,7 @@
 #include <linux/of_platform.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
+#include <linux/string_choices.h>
 
 static DEFINE_IDA(fpga_bridge_ida);
 static const struct class fpga_bridge_class;
@@ -305,7 +306,7 @@ static ssize_t state_show(struct device *dev,
 			return state;
 	}
 
-	return sysfs_emit(buf, "%s\n", state ? "enabled" : "disabled");
+	return sysfs_emit(buf, "%s\n", str_enabled_disabled(state));
 }
 
 static DEVICE_ATTR_RO(name);
Signature · 2 lines
Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
#1 lore raw

Hi Thorsten,

Quoted 22 lines · Thorsten Blum

Replace hard-coded strings with the str_enabled_disabled() helper. This unifies the output and helps the linker with deduplication, which can result in a smaller binary.

---
  drivers/fpga/fpga-bridge.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/fpga/fpga-bridge.c +1 -0
index ca68c38aa4a1..e8ff3e3bf2fc 100644
@@ -12,6 +12,7 @@
  #include <linux/of_platform.h>
  #include <linux/slab.h>
  #include <linux/spinlock.h>
+#include <linux/string_choices.h>
 
  static DEFINE_IDA(fpga_bridge_ida);
  static const struct class fpga_bridge_class;

drivers/fpga/fpga-bridge.c static ssize_t state_show(struct device *dev, · line 312

Quoted 8 lines
drivers/fpga/fpga-bridge.c +1 -1
@@ -305,7 +306,7 @@ static ssize_t state_show(struct device *dev,
  			return state;
  	}
 
-	return sysfs_emit(buf, "%s\n", state ? "enabled" : "disabled");
+	return sysfs_emit(buf, "%s\n", str_enabled_disabled(state));
  }
 
  static DEVICE_ATTR_RO(name);

Would you consider including this patch[1] to this?

Dinh
[1] https://lore.kernel.org/linux-fpga/aXH2D06eZ5DRTVi0@yilunxu-OptiPlex-7050/

#2 lore raw
Quoted 24 lines · Dinh Nguyen

Hi Thorsten,

Quoted 21 lines · Thorsten Blum

Replace hard-coded strings with the str_enabled_disabled() helper. This unifies the output and helps the linker with deduplication, which can result in a smaller binary.

---
  drivers/fpga/fpga-bridge.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/fpga/fpga-bridge.c +1 -0
index ca68c38aa4a1..e8ff3e3bf2fc 100644
@@ -12,6 +12,7 @@
  #include <linux/of_platform.h>
  #include <linux/slab.h>
  #include <linux/spinlock.h>
+#include <linux/string_choices.h>
  static DEFINE_IDA(fpga_bridge_ida);
  static const struct class fpga_bridge_class;
@@ -305,7 +306,7 @@ static ssize_t state_show(struct device *dev,
Quoted 8 lines

drivers/fpga/fpga-bridge.c static ssize_t state_show(struct device *dev, · line 312

Quoted 6 lines
drivers/fpga/fpga-bridge.c +1 -1
  			return state;
  	}
-	return sysfs_emit(buf, "%s\n", state ? "enabled" : "disabled");
+	return sysfs_emit(buf, "%s\n", str_enabled_disabled(state));
  }
  static DEVICE_ATTR_RO(name);

Would you consider including this patch[1] to this?

Oh... This str_enabled_disabled() is exactly the same trivial changes I was thinking of when I wrote that comment.

Quoted 4 lines

Dinh
[1]
https://lore.kernel.org/linux-fpga/aXH2D06eZ5DRTVi0@yilunxu-OptiPlex-7050/

But hi Dinh, took another look, the state_show() in the same file is already switched to sysfs_emit() by previous valid change. So to keep the file consistency, it's good to change to sysfs_emit() for name_show(). Sorry for my neglection.

Quoted 1 line