Commit 003504a2 authored by David S. Miller's avatar David S. Miller

Merge branch 'net-sched-actions-code-style-cleanup-and-fixes'

Roman Mashak says:

====================
net sched actions: code style cleanup and fixes

The patchset fixes a few code stylistic issues and typos, as well as one
detected by sparse semantic checker tool.

No functional changes introduced.

Patch 1 & 2 fix coding style bits caught by the checkpatch.pl script
Patch 3 fixes an issue with a shadowed variable
Patch 4 adds sizeof() operator instead of magic number for buffer length
Patch 5 fixes typos in diagnostics messages
Patch 6 explicitly sets unsigned char for bitwise operation

v2:
   - submit for net-next
   - added Reviewed-by tags
   - use u8* instead of char* as per Davide Caratti suggestion
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 0a9fe5c3 43052741
...@@ -17,6 +17,7 @@ struct tcf_pedit { ...@@ -17,6 +17,7 @@ struct tcf_pedit {
struct tc_pedit_key *tcfp_keys; struct tc_pedit_key *tcfp_keys;
struct tcf_pedit_key_ex *tcfp_keys_ex; struct tcf_pedit_key_ex *tcfp_keys_ex;
}; };
#define to_pedit(a) ((struct tcf_pedit *)a) #define to_pedit(a) ((struct tcf_pedit *)a)
static inline bool is_tcf_pedit(const struct tc_action *a) static inline bool is_tcf_pedit(const struct tc_action *a)
......
...@@ -17,6 +17,7 @@ enum { ...@@ -17,6 +17,7 @@ enum {
TCA_PEDIT_KEY_EX, TCA_PEDIT_KEY_EX,
__TCA_PEDIT_MAX __TCA_PEDIT_MAX
}; };
#define TCA_PEDIT_MAX (__TCA_PEDIT_MAX - 1) #define TCA_PEDIT_MAX (__TCA_PEDIT_MAX - 1)
enum { enum {
...@@ -24,6 +25,7 @@ enum { ...@@ -24,6 +25,7 @@ enum {
TCA_PEDIT_KEY_EX_CMD = 2, TCA_PEDIT_KEY_EX_CMD = 2,
__TCA_PEDIT_KEY_EX_MAX __TCA_PEDIT_KEY_EX_MAX
}; };
#define TCA_PEDIT_KEY_EX_MAX (__TCA_PEDIT_KEY_EX_MAX - 1) #define TCA_PEDIT_KEY_EX_MAX (__TCA_PEDIT_KEY_EX_MAX - 1)
/* TCA_PEDIT_KEY_EX_HDR_TYPE_NETWROK is a special case for legacy users. It /* TCA_PEDIT_KEY_EX_HDR_TYPE_NETWROK is a special case for legacy users. It
...@@ -38,6 +40,7 @@ enum pedit_header_type { ...@@ -38,6 +40,7 @@ enum pedit_header_type {
TCA_PEDIT_KEY_EX_HDR_TYPE_UDP = 5, TCA_PEDIT_KEY_EX_HDR_TYPE_UDP = 5,
__PEDIT_HDR_TYPE_MAX, __PEDIT_HDR_TYPE_MAX,
}; };
#define TCA_PEDIT_HDR_TYPE_MAX (__PEDIT_HDR_TYPE_MAX - 1) #define TCA_PEDIT_HDR_TYPE_MAX (__PEDIT_HDR_TYPE_MAX - 1)
enum pedit_cmd { enum pedit_cmd {
...@@ -45,6 +48,7 @@ enum pedit_cmd { ...@@ -45,6 +48,7 @@ enum pedit_cmd {
TCA_PEDIT_KEY_EX_CMD_ADD = 1, TCA_PEDIT_KEY_EX_CMD_ADD = 1,
__PEDIT_CMD_MAX, __PEDIT_CMD_MAX,
}; };
#define TCA_PEDIT_CMD_MAX (__PEDIT_CMD_MAX - 1) #define TCA_PEDIT_CMD_MAX (__PEDIT_CMD_MAX - 1)
struct tc_pedit_key { struct tc_pedit_key {
...@@ -62,6 +66,7 @@ struct tc_pedit_sel { ...@@ -62,6 +66,7 @@ struct tc_pedit_sel {
unsigned char flags; unsigned char flags;
struct tc_pedit_key keys[0]; struct tc_pedit_key keys[0];
}; };
#define tc_pedit tc_pedit_sel #define tc_pedit tc_pedit_sel
#endif #endif
...@@ -136,15 +136,15 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla, ...@@ -136,15 +136,15 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
{ {
struct tc_action_net *tn = net_generic(net, pedit_net_id); struct tc_action_net *tn = net_generic(net, pedit_net_id);
struct nlattr *tb[TCA_PEDIT_MAX + 1]; struct nlattr *tb[TCA_PEDIT_MAX + 1];
struct nlattr *pattr;
struct tc_pedit *parm;
int ret = 0, err;
struct tcf_pedit *p;
struct tc_pedit_key *keys = NULL; struct tc_pedit_key *keys = NULL;
struct tcf_pedit_key_ex *keys_ex; struct tcf_pedit_key_ex *keys_ex;
struct tc_pedit *parm;
struct nlattr *pattr;
struct tcf_pedit *p;
int ret = 0, err;
int ksize; int ksize;
if (nla == NULL) if (!nla)
return -EINVAL; return -EINVAL;
err = nla_parse_nested(tb, TCA_PEDIT_MAX, nla, pedit_policy, NULL); err = nla_parse_nested(tb, TCA_PEDIT_MAX, nla, pedit_policy, NULL);
...@@ -175,7 +175,7 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla, ...@@ -175,7 +175,7 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
return ret; return ret;
p = to_pedit(*a); p = to_pedit(*a);
keys = kmalloc(ksize, GFP_KERNEL); keys = kmalloc(ksize, GFP_KERNEL);
if (keys == NULL) { if (!keys) {
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
kfree(keys_ex); kfree(keys_ex);
return -ENOMEM; return -ENOMEM;
...@@ -220,6 +220,7 @@ static void tcf_pedit_cleanup(struct tc_action *a) ...@@ -220,6 +220,7 @@ static void tcf_pedit_cleanup(struct tc_action *a)
{ {
struct tcf_pedit *p = to_pedit(a); struct tcf_pedit *p = to_pedit(a);
struct tc_pedit_key *keys = p->tcfp_keys; struct tc_pedit_key *keys = p->tcfp_keys;
kfree(keys); kfree(keys);
kfree(p->tcfp_keys_ex); kfree(p->tcfp_keys_ex);
} }
...@@ -284,11 +285,12 @@ static int tcf_pedit(struct sk_buff *skb, const struct tc_action *a, ...@@ -284,11 +285,12 @@ static int tcf_pedit(struct sk_buff *skb, const struct tc_action *a,
if (p->tcfp_nkeys > 0) { if (p->tcfp_nkeys > 0) {
struct tc_pedit_key *tkey = p->tcfp_keys; struct tc_pedit_key *tkey = p->tcfp_keys;
struct tcf_pedit_key_ex *tkey_ex = p->tcfp_keys_ex; struct tcf_pedit_key_ex *tkey_ex = p->tcfp_keys_ex;
enum pedit_header_type htype = TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK; enum pedit_header_type htype =
TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK;
enum pedit_cmd cmd = TCA_PEDIT_KEY_EX_CMD_SET; enum pedit_cmd cmd = TCA_PEDIT_KEY_EX_CMD_SET;
for (i = p->tcfp_nkeys; i > 0; i--, tkey++) { for (i = p->tcfp_nkeys; i > 0; i--, tkey++) {
u32 *ptr, _data; u32 *ptr, hdata;
int offset = tkey->off; int offset = tkey->off;
int hoffset; int hoffset;
u32 val; u32 val;
...@@ -303,39 +305,39 @@ static int tcf_pedit(struct sk_buff *skb, const struct tc_action *a, ...@@ -303,39 +305,39 @@ static int tcf_pedit(struct sk_buff *skb, const struct tc_action *a,
rc = pedit_skb_hdr_offset(skb, htype, &hoffset); rc = pedit_skb_hdr_offset(skb, htype, &hoffset);
if (rc) { if (rc) {
pr_info("tc filter pedit bad header type specified (0x%x)\n", pr_info("tc action pedit bad header type specified (0x%x)\n",
htype); htype);
goto bad; goto bad;
} }
if (tkey->offmask) { if (tkey->offmask) {
char *d, _d; u8 *d, _d;
if (!offset_valid(skb, hoffset + tkey->at)) { if (!offset_valid(skb, hoffset + tkey->at)) {
pr_info("tc filter pedit 'at' offset %d out of bounds\n", pr_info("tc action pedit 'at' offset %d out of bounds\n",
hoffset + tkey->at); hoffset + tkey->at);
goto bad; goto bad;
} }
d = skb_header_pointer(skb, hoffset + tkey->at, 1, d = skb_header_pointer(skb, hoffset + tkey->at,
&_d); sizeof(_d), &_d);
if (!d) if (!d)
goto bad; goto bad;
offset += (*d & tkey->offmask) >> tkey->shift; offset += (*d & tkey->offmask) >> tkey->shift;
} }
if (offset % 4) { if (offset % 4) {
pr_info("tc filter pedit" pr_info("tc action pedit offset must be on 32 bit boundaries\n");
" offset must be on 32 bit boundaries\n");
goto bad; goto bad;
} }
if (!offset_valid(skb, hoffset + offset)) { if (!offset_valid(skb, hoffset + offset)) {
pr_info("tc filter pedit offset %d out of bounds\n", pr_info("tc action pedit offset %d out of bounds\n",
hoffset + offset); hoffset + offset);
goto bad; goto bad;
} }
ptr = skb_header_pointer(skb, hoffset + offset, 4, &_data); ptr = skb_header_pointer(skb, hoffset + offset,
sizeof(hdata), &hdata);
if (!ptr) if (!ptr)
goto bad; goto bad;
/* just do it, baby */ /* just do it, baby */
...@@ -347,19 +349,20 @@ static int tcf_pedit(struct sk_buff *skb, const struct tc_action *a, ...@@ -347,19 +349,20 @@ static int tcf_pedit(struct sk_buff *skb, const struct tc_action *a,
val = (*ptr + tkey->val) & ~tkey->mask; val = (*ptr + tkey->val) & ~tkey->mask;
break; break;
default: default:
pr_info("tc filter pedit bad command (%d)\n", pr_info("tc action pedit bad command (%d)\n",
cmd); cmd);
goto bad; goto bad;
} }
*ptr = ((*ptr & tkey->mask) ^ val); *ptr = ((*ptr & tkey->mask) ^ val);
if (ptr == &_data) if (ptr == &hdata)
skb_store_bits(skb, hoffset + offset, ptr, 4); skb_store_bits(skb, hoffset + offset, ptr, 4);
} }
goto done; goto done;
} else } else {
WARN(1, "pedit BUG: index %d\n", p->tcf_index); WARN(1, "pedit BUG: index %d\n", p->tcf_index);
}
bad: bad:
p->tcf_qstats.overlimits++; p->tcf_qstats.overlimits++;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment