diff mbox series

[net-next] net: Use str_yes_no() and str_no_yes() helper functions

Message ID 20241026112946.129310-2-thorsten.blum@linux.dev (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: Use str_yes_no() and str_no_yes() helper functions | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5 this patch: 5
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch warning CHECK: Comparison to NULL could be written "!proto->slab"
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 9 this patch: 9
netdev/source_inline success Was 0 now: 0

Commit Message

Thorsten Blum Oct. 26, 2024, 11:29 a.m. UTC
Remove hard-coded strings by using the str_yes_no() and str_no_yes()
helper functions.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 net/core/sock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Willem de Bruijn Oct. 26, 2024, 2:54 p.m. UTC | #1
Thorsten Blum wrote:
> Remove hard-coded strings by using the str_yes_no() and str_no_yes()
> helper functions.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  net/core/sock.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/net/core/sock.c b/net/core/sock.c
> index 039be95c40cf..132c8d2cda26 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -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),

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.
Thorsten Blum Oct. 26, 2024, 3:14 p.m. UTC | #2
On 26. Oct 2024, at 16:54, Willem de Bruijn wrote:
> 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.
diff mbox series

Patch

diff --git a/net/core/sock.c b/net/core/sock.c
index 039be95c40cf..132c8d2cda26 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -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),