Skip to content

Commit c75a33c

Browse files
jacob-kellerdavem330
authored andcommitted
net: remove newlines in NL_SET_ERR_MSG_MOD
The NL_SET_ERR_MSG_MOD macro is used to report a string describing an error message to userspace via the netlink extended ACK structure. It should not have a trailing newline. Add a cocci script which catches cases where the newline marker is present. Using this script, fix the handful of cases which accidentally included a trailing new line. I couldn't figure out a way to get a patch mode working, so this script only implements context, report, and org. Signed-off-by: Jacob Keller <jacob.e.keller@intel.com> Cc: Jakub Kicinski <kuba@kernel.org> Cc: Andy Whitcroft <apw@canonical.com> Cc: Joe Perches <joe@perches.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 57ea850 commit c75a33c

6 files changed

Lines changed: 84 additions & 9 deletions

File tree

‎drivers/net/ethernet/mellanox/mlx5/core/en_tc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ mlx5e_tc_add_nic_flow(struct mlx5e_priv *priv,
10971097
if (IS_ERR(priv->fs.tc.t)) {
10981098
mutex_unlock(&priv->fs.tc.t_lock);
10991099
NL_SET_ERR_MSG_MOD(extack,
1100-
"Failed to create tc offload table\n");
1100+
"Failed to create tc offload table");
11011101
netdev_err(priv->netdev,
11021102
"Failed to create tc offload table\n");
11031103
return PTR_ERR(priv->fs.tc.t);

‎drivers/net/ethernet/mscc/ocelot_tc.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static int ocelot_setup_tc_cls_matchall(struct ocelot_port_private *priv,
4848

4949
if (priv->tc.police_id && priv->tc.police_id != f->cookie) {
5050
NL_SET_ERR_MSG_MOD(extack,
51-
"Only one policer per port is supported\n");
51+
"Only one policer per port is supported");
5252
return -EEXIST;
5353
}
5454

@@ -59,7 +59,7 @@ static int ocelot_setup_tc_cls_matchall(struct ocelot_port_private *priv,
5959

6060
err = ocelot_port_policer_add(ocelot, port, &pol);
6161
if (err) {
62-
NL_SET_ERR_MSG_MOD(extack, "Could not add policer\n");
62+
NL_SET_ERR_MSG_MOD(extack, "Could not add policer");
6363
return err;
6464
}
6565

@@ -73,7 +73,7 @@ static int ocelot_setup_tc_cls_matchall(struct ocelot_port_private *priv,
7373
err = ocelot_port_policer_del(ocelot, port);
7474
if (err) {
7575
NL_SET_ERR_MSG_MOD(extack,
76-
"Could not delete policer\n");
76+
"Could not delete policer");
7777
return err;
7878
}
7979
priv->tc.police_id = 0;

‎net/bridge/br_mrp_netlink.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p,
2828
int err;
2929

3030
if (br->stp_enabled != BR_NO_STP) {
31-
NL_SET_ERR_MSG_MOD(extack, "MRP can't be enabled if STP is already enabled\n");
31+
NL_SET_ERR_MSG_MOD(extack, "MRP can't be enabled if STP is already enabled");
3232
return -EINVAL;
3333
}
3434

‎net/bridge/br_stp_if.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ int br_stp_set_enabled(struct net_bridge *br, unsigned long val,
203203

204204
if (br_mrp_enabled(br)) {
205205
NL_SET_ERR_MSG_MOD(extack,
206-
"STP can't be enabled if MRP is already enabled\n");
206+
"STP can't be enabled if MRP is already enabled");
207207
return -EINVAL;
208208
}
209209

‎net/dsa/slave.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -911,13 +911,13 @@ dsa_slave_add_cls_matchall_police(struct net_device *dev,
911911

912912
if (!ds->ops->port_policer_add) {
913913
NL_SET_ERR_MSG_MOD(extack,
914-
"Policing offload not implemented\n");
914+
"Policing offload not implemented");
915915
return -EOPNOTSUPP;
916916
}
917917

918918
if (!ingress) {
919919
NL_SET_ERR_MSG_MOD(extack,
920-
"Only supported on ingress qdisc\n");
920+
"Only supported on ingress qdisc");
921921
return -EOPNOTSUPP;
922922
}
923923

@@ -928,7 +928,7 @@ dsa_slave_add_cls_matchall_police(struct net_device *dev,
928928
list_for_each_entry(mall_tc_entry, &p->mall_tc_list, list) {
929929
if (mall_tc_entry->type == DSA_PORT_MALL_POLICER) {
930930
NL_SET_ERR_MSG_MOD(extack,
931-
"Only one port policer allowed\n");
931+
"Only one port policer allowed");
932932
return -EEXIST;
933933
}
934934
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
///
3+
/// Catch strings ending in newline with GENL_SET_ERR_MSG, NL_SET_ERR_MSG,
4+
/// NL_SET_ERR_MSG_MOD.
5+
///
6+
// Confidence: Very High
7+
// Copyright: (C) 2020 Intel Corporation
8+
// URL: http://coccinelle.lip6.fr/
9+
// Options: --no-includes --include-headers
10+
11+
virtual context
12+
virtual org
13+
virtual report
14+
15+
@r depends on context || org || report@
16+
expression e;
17+
constant m;
18+
position p;
19+
@@
20+
\(GENL_SET_ERR_MSG\|NL_SET_ERR_MSG\|NL_SET_ERR_MSG_MOD\)(e,m@p)
21+
22+
@script:python@
23+
m << r.m;
24+
@@
25+
26+
if not m.endswith("\\n\""):
27+
cocci.include_match(False)
28+
29+
@r1 depends on r@
30+
identifier fname;
31+
expression r.e;
32+
constant r.m;
33+
position r.p;
34+
@@
35+
fname(e,m@p)
36+
37+
//----------------------------------------------------------
38+
// For context mode
39+
//----------------------------------------------------------
40+
41+
@depends on context && r@
42+
identifier r1.fname;
43+
expression r.e;
44+
constant r.m;
45+
@@
46+
* fname(e,m)
47+
48+
//----------------------------------------------------------
49+
// For org mode
50+
//----------------------------------------------------------
51+
52+
@script:python depends on org@
53+
fname << r1.fname;
54+
m << r.m;
55+
p << r.p;
56+
@@
57+
58+
if m.endswith("\\n\""):
59+
msg="WARNING avoid newline at end of message in %s" % (fname)
60+
msg_safe=msg.replace("[","@(").replace("]",")")
61+
coccilib.org.print_todo(p[0], msg_safe)
62+
63+
//----------------------------------------------------------
64+
// For report mode
65+
//----------------------------------------------------------
66+
67+
@script:python depends on report@
68+
fname << r1.fname;
69+
m << r.m;
70+
p << r.p;
71+
@@
72+
73+
if m.endswith("\\n\""):
74+
msg="WARNING avoid newline at end of message in %s" % (fname)
75+
coccilib.report.print_report(p[0], msg)

0 commit comments

Comments
 (0)