Skip to contentSkip to conversation

net: Use str_yes_no() and str_no_yes() helper functions

PATCH In review Thorsten Blum 2 participants 3 messages Oct 26, 2024

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

PATCH 1/1 net: Use str_yes_no() and str_no_yes() helper functions

Remove hard-coded strings by using the str_yes_no() and str_no_yes() helper functions.

---
 net/core/sock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/sock.c +2 -2
index 039be95c40cf..132c8d2cda26 100644
@@ -4140,7 +4140,7 @@ static long sock_prot_memory_allocated(struct proto *proto)
 static const char *sock_prot_memory_pressure(struct proto *proto)
 {
 	return proto->memory_pressure != NULL ?
-	proto_memory_pressure(proto) ? "yes" : "no" : "NI";
+		str_yes_no(proto_memory_pressure(proto)) : "NI";
 }
 
 static void proto_seq_printf(struct seq_file *seq, struct proto *proto)
@@ -4154,7 +4154,7 @@ static void proto_seq_printf(struct seq_file *seq, struct proto *proto)
 		   sock_prot_memory_allocated(proto),
 		   sock_prot_memory_pressure(proto),
 		   proto->max_header,
-		   proto->slab == NULL ? "no" : "yes",
+		   str_no_yes(proto->slab == NULL),
 		   module_name(proto->owner),
 		   proto_method_implemented(proto->close),
 		   proto_method_implemented(proto->connect),
Signature · 1 line
2.47.0
#1 lore raw
Quoted 22 lines · Thorsten Blum

Remove hard-coded strings by using the str_yes_no() and str_no_yes() helper functions.

---
 net/core/sock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/sock.c +1 -1
index 039be95c40cf..132c8d2cda26 100644
@@ -4140,7 +4140,7 @@ static long sock_prot_memory_allocated(struct proto *proto)
 static const char *sock_prot_memory_pressure(struct proto *proto)
 {
 	return proto->memory_pressure != NULL ?
-	proto_memory_pressure(proto) ? "yes" : "no" : "NI";
+		str_yes_no(proto_memory_pressure(proto)) : "NI";
 }
 
 static void proto_seq_printf(struct seq_file *seq, struct proto *proto)

net/core/sock.c static void proto_seq_printf(struct seq_file *seq, struct proto *proto) · line 4157

Quoted 5 lines
net/core/sock.c +1 -1
@@ -4154,7 +4154,7 @@ static void proto_seq_printf(struct seq_file *seq, struct proto *proto)
 		   sock_prot_memory_allocated(proto),
 		   sock_prot_memory_pressure(proto),
 		   proto->max_header,
-		   proto->slab == NULL ? "no" : "yes",
+		   str_no_yes(proto->slab == NULL),

Just one opinion, but to reiterate from a previous similar patch:

I find this less readable than the original open code variant.

include/linux/string_choices.h mentions three goals: elegance, consistency and binary size. The third goal could be an argument for this change perhaps.

proto->slab : "yes" : "no" would arguably be even easier than the current form, and a conversion could similarly use str_yes_no.

#2 lore raw
Quoted 2 lines · Willem de Bruijn

proto->slab : "yes" : "no" would arguably be even easier than the current form, and a conversion could similarly use str_yes_no.

Happy to change this and submit a v2.