Skip to contentSkip to conversation

evaluate: Follow linux-kernel coding style

PATCH In review Harsha Sharma 2 participants 5 messages Oct 2, 2017 – Oct 4, 2017 netfilter

lore
Share & tools
lore
#0 lore raw

cover evaluate: Follow linux-kernel coding style

Issues found using checkpatch.pl
As per linux-kernel coding style, code indent should use tabs wherever possible and avoid unnecessary spaces.
Comparisons shoukd place the constant on the right side of the test. static const char * array should be static const * char const array

Harsha Sharma (3):
evaluate: Remove unnecessary spaces
evaluate: Place constant on right side in comparison
evaluate: fix checkpatch issue for static const char * array

 src/evaluate.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/3 evaluate: Remove unnecessary spaces

Code indent should use tabs wherever possible

---
 src/evaluate.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
src/evaluate.c +5 -5
index e767542..5624ca2 100644
@@ -122,7 +122,7 @@ static int byteorder_conversion(struct eval_ctx *ctx, struct expr **expr,
 		return 0;
 	if (expr_basetype(*expr)->type != TYPE_INTEGER)
 		return expr_error(ctx->msgs, *expr,
-			 	  "Byteorder mismatch: expected %s, got %s",
+				  "Byteorder mismatch: expected %s, got %s",
 				  byteorder_names[byteorder],
 				  byteorder_names[(*expr)->byteorder]);
 
@@ -1321,7 +1321,7 @@ static int expr_evaluate_hash(struct eval_ctx *ctx, struct expr **exprp)
 		return -1;
 
 	/* expr_evaluate_primary() sets the context to what to the input
-         * expression to be hashed. Since this input is transformed to a 4 bytes
+	 * expression to be hashed. Since this input is transformed to a 4 bytes
 	 * integer, restore context to the datatype that results from hashing.
 	 */
 	__expr_set_context(&ctx->ectx, expr->dtype, expr->byteorder, expr->len,
@@ -1627,7 +1627,7 @@ static int expr_evaluate_relational(struct eval_ctx *ctx, struct expr **expr)
 		case EXPR_CONCAT:
 			return expr_binary_error(ctx->msgs, left, rel,
 					"Relational expression (%s) is undefined "
-				        "for %s expressions",
+					"for %s expressions",
 					expr_op_symbols[rel->op],
 					left->ops->name);
 		default:
@@ -1637,7 +1637,7 @@ static int expr_evaluate_relational(struct eval_ctx *ctx, struct expr **expr)
 		if (!expr_is_singleton(right))
 			return expr_binary_error(ctx->msgs, right, rel,
 					"Relational expression (%s) is undefined "
-				        "for %s expressions",
+					"for %s expressions",
 					expr_op_symbols[rel->op],
 					right->ops->name);
 
@@ -1659,7 +1659,7 @@ range:
 		case EXPR_CONCAT:
 			return expr_binary_error(ctx->msgs, left, rel,
 					"Relational expression (%s) is undefined"
-				        "for %s expressions",
+					"for %s expressions",
 					expr_op_symbols[rel->op],
 					left->ops->name);
 		default:
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/3 evaluate: Place constant on right side in comparison

In reply to Harsha Sharma

Comparisons should place the constant on the right side of the test as per linux-kernel coding style

---
 src/evaluate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/evaluate.c +2 -2
index 5624ca2..b783054 100644
@@ -2174,13 +2174,13 @@ static int stmt_evaluate_reject_bridge_family(struct eval_ctx *ctx,
 		protocol = proto_find_num(base, desc);
 		switch (protocol) {
 		case __constant_htons(ETH_P_IP):
-			if (NFPROTO_IPV4 == stmt->reject.family)
+			if (stmt->reject.family == NFPROTO_IPV4)
 				break;
 			return stmt_binary_error(ctx, stmt->reject.expr,
 				  &ctx->pctx.protocol[PROTO_BASE_NETWORK_HDR],
 				  "conflicting protocols specified: ip vs ip6");
 		case __constant_htons(ETH_P_IPV6):
-			if (NFPROTO_IPV6 == stmt->reject.family)
+			if (stmt->reject.family == NFPROTO_IPV6)
 				break;
 			return stmt_binary_error(ctx, stmt->reject.expr,
 				  &ctx->pctx.protocol[PROTO_BASE_NETWORK_HDR],
Signature · 1 line
1.9.1
#3 lore raw

PATCH 3/3 evaluate: make pointers in string arrays constant

In reply to Harsha Sharma

static const char * array should probably be static const char * const array
as per linux-kernel coding style

---
 src/evaluate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/evaluate.c +2 -2
index b783054..f48801a 100644
@@ -33,7 +33,7 @@
 static struct output_ctx octx_debug_dummy;
 static int expr_evaluate(struct eval_ctx *ctx, struct expr **expr);
 
-static const char *byteorder_names[] = {
+static const char * const byteorder_names[] = {
 	[BYTEORDER_INVALID]		= "invalid",
 	[BYTEORDER_HOST_ENDIAN]		= "host endian",
 	[BYTEORDER_BIG_ENDIAN]		= "big endian",
@@ -3350,7 +3350,7 @@ static int cmd_evaluate_export(struct eval_ctx *ctx, struct cmd *cmd)
 			    ctx->debug_mask & DEBUG_NETLINK);
 }
 
-static const char *cmd_op_name[] = {
+static const char * const cmd_op_name[] = {
 	[CMD_INVALID]	= "invalid",
 	[CMD_ADD]	= "add",
 	[CMD_REPLACE]	= "replace",
Signature · 1 line
1.9.1
#4 lore raw

Re: [Outreachy kernel] [PATCH 3/3] evaluate: make pointers in string arrays constant

Quoted 14 lines · Harsha Sharma

static const char * array should probably be static const char * const array
as per linux-kernel coding style

---
 src/evaluate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/evaluate.c +0 -0
index b783054..f48801a 100644

src/evaluate.c line 36

Quoted 5 lines
src/evaluate.c +1 -1
@@ -33,7 +33,7 @@
 static struct output_ctx octx_debug_dummy;
 static int expr_evaluate(struct eval_ctx *ctx, struct expr **expr);
 
-static const char *byteorder_names[] = {
+static const char * const byteorder_names[] = {

I can see more string array that could use this in the nftables tree. Please, fix all in one single patch.

Thanks.