Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jacob Keller and committed by
David S. Miller
c75a33c8 57ea8506

+84 -9
+1 -1
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
··· 1097 1097 if (IS_ERR(priv->fs.tc.t)) { 1098 1098 mutex_unlock(&priv->fs.tc.t_lock); 1099 1099 NL_SET_ERR_MSG_MOD(extack, 1100 - "Failed to create tc offload table\n"); 1100 + "Failed to create tc offload table"); 1101 1101 netdev_err(priv->netdev, 1102 1102 "Failed to create tc offload table\n"); 1103 1103 return PTR_ERR(priv->fs.tc.t);
+3 -3
drivers/net/ethernet/mscc/ocelot_tc.c
··· 48 48 49 49 if (priv->tc.police_id && priv->tc.police_id != f->cookie) { 50 50 NL_SET_ERR_MSG_MOD(extack, 51 - "Only one policer per port is supported\n"); 51 + "Only one policer per port is supported"); 52 52 return -EEXIST; 53 53 } 54 54 ··· 59 59 60 60 err = ocelot_port_policer_add(ocelot, port, &pol); 61 61 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"); 63 63 return err; 64 64 } 65 65 ··· 73 73 err = ocelot_port_policer_del(ocelot, port); 74 74 if (err) { 75 75 NL_SET_ERR_MSG_MOD(extack, 76 - "Could not delete policer\n"); 76 + "Could not delete policer"); 77 77 return err; 78 78 } 79 79 priv->tc.police_id = 0;
+1 -1
net/bridge/br_mrp_netlink.c
··· 28 28 int err; 29 29 30 30 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"); 32 32 return -EINVAL; 33 33 } 34 34
+1 -1
net/bridge/br_stp_if.c
··· 203 203 204 204 if (br_mrp_enabled(br)) { 205 205 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"); 207 207 return -EINVAL; 208 208 } 209 209
+3 -3
net/dsa/slave.c
··· 911 911 912 912 if (!ds->ops->port_policer_add) { 913 913 NL_SET_ERR_MSG_MOD(extack, 914 - "Policing offload not implemented\n"); 914 + "Policing offload not implemented"); 915 915 return -EOPNOTSUPP; 916 916 } 917 917 918 918 if (!ingress) { 919 919 NL_SET_ERR_MSG_MOD(extack, 920 - "Only supported on ingress qdisc\n"); 920 + "Only supported on ingress qdisc"); 921 921 return -EOPNOTSUPP; 922 922 } 923 923 ··· 928 928 list_for_each_entry(mall_tc_entry, &p->mall_tc_list, list) { 929 929 if (mall_tc_entry->type == DSA_PORT_MALL_POLICER) { 930 930 NL_SET_ERR_MSG_MOD(extack, 931 - "Only one port policer allowed\n"); 931 + "Only one port policer allowed"); 932 932 return -EEXIST; 933 933 } 934 934 }
+75
scripts/coccinelle/misc/newline_in_nl_msg.cocci
··· 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)