Skip to contentSkip to conversation

kernel/params.c: Refactor dash2underscore

PATCH In review Jim Christian Haukvik 2 participants 2 messages Oct 23, 2021 – Oct 24, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel/params.c: Refactor dash2underscore

This patch refactors the dash2underscore function
to use the ternary operator.

---
 kernel/params.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/params.c +1 -3
index 8299bd764e42..865a76fec79a 100644
@@ -76,9 +76,7 @@ static void maybe_kfree_parameter(void *param)
 
 static char dash2underscore(char c)
 {
-	if (c == '-')
-		return '_';
-	return c;
+	return (c == '-') ? '_' : c;
 }
 
 bool parameqn(const char *a, const char *b, size_t n)
Signature · 1 line
2.33.1
#1 lore raw
Quoted 13 lines · Jim Christian Haukvik

This patch refactors the dash2underscore function
to use the ternary operator.

---
 kernel/params.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/params.c +0 -0
index 8299bd764e42..865a76fec79a 100644

kernel/params.c static void maybe_kfree_parameter(void *param) · line 80

Quoted 8 lines
kernel/params.c +1 -3
@@ -76,9 +76,7 @@ static void maybe_kfree_parameter(void *param)
 
 static char dash2underscore(char c)
 {
-	if (c == '-')
-		return '_';
-	return c;
+	return (c == '-') ? '_' : c;
 }

This is not an improvement. You're just making the code harder to read for no good reason (the ternary operator tends to do so).

Johan