Skip to content

Commit 003504a

Browse files
committed
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: David S. Miller <[email protected]>
2 parents 0a9fe5c + 4305274 commit 003504a

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

include/net/tc_act/tc_pedit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct tcf_pedit {
1717
struct tc_pedit_key *tcfp_keys;
1818
struct tcf_pedit_key_ex *tcfp_keys_ex;
1919
};
20+
2021
#define to_pedit(a) ((struct tcf_pedit *)a)
2122

2223
static inline bool is_tcf_pedit(const struct tc_action *a)

include/uapi/linux/tc_act/tc_pedit.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ enum {
1717
TCA_PEDIT_KEY_EX,
1818
__TCA_PEDIT_MAX
1919
};
20+
2021
#define TCA_PEDIT_MAX (__TCA_PEDIT_MAX - 1)
21-
22+
2223
enum {
2324
TCA_PEDIT_KEY_EX_HTYPE = 1,
2425
TCA_PEDIT_KEY_EX_CMD = 2,
2526
__TCA_PEDIT_KEY_EX_MAX
2627
};
28+
2729
#define TCA_PEDIT_KEY_EX_MAX (__TCA_PEDIT_KEY_EX_MAX - 1)
2830

2931
/* TCA_PEDIT_KEY_EX_HDR_TYPE_NETWROK is a special case for legacy users. It
@@ -38,13 +40,15 @@ enum pedit_header_type {
3840
TCA_PEDIT_KEY_EX_HDR_TYPE_UDP = 5,
3941
__PEDIT_HDR_TYPE_MAX,
4042
};
43+
4144
#define TCA_PEDIT_HDR_TYPE_MAX (__PEDIT_HDR_TYPE_MAX - 1)
4245

4346
enum pedit_cmd {
4447
TCA_PEDIT_KEY_EX_CMD_SET = 0,
4548
TCA_PEDIT_KEY_EX_CMD_ADD = 1,
4649
__PEDIT_CMD_MAX,
4750
};
51+
4852
#define TCA_PEDIT_CMD_MAX (__PEDIT_CMD_MAX - 1)
4953

5054
struct tc_pedit_key {
@@ -55,13 +59,14 @@ struct tc_pedit_key {
5559
__u32 offmask;
5660
__u32 shift;
5761
};
58-
62+
5963
struct tc_pedit_sel {
6064
tc_gen;
6165
unsigned char nkeys;
6266
unsigned char flags;
6367
struct tc_pedit_key keys[0];
6468
};
69+
6570
#define tc_pedit tc_pedit_sel
6671

6772
#endif

net/sched/act_pedit.c

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,15 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
136136
{
137137
struct tc_action_net *tn = net_generic(net, pedit_net_id);
138138
struct nlattr *tb[TCA_PEDIT_MAX + 1];
139-
struct nlattr *pattr;
140-
struct tc_pedit *parm;
141-
int ret = 0, err;
142-
struct tcf_pedit *p;
143139
struct tc_pedit_key *keys = NULL;
144140
struct tcf_pedit_key_ex *keys_ex;
141+
struct tc_pedit *parm;
142+
struct nlattr *pattr;
143+
struct tcf_pedit *p;
144+
int ret = 0, err;
145145
int ksize;
146146

147-
if (nla == NULL)
147+
if (!nla)
148148
return -EINVAL;
149149

150150
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,
175175
return ret;
176176
p = to_pedit(*a);
177177
keys = kmalloc(ksize, GFP_KERNEL);
178-
if (keys == NULL) {
178+
if (!keys) {
179179
tcf_idr_release(*a, bind);
180180
kfree(keys_ex);
181181
return -ENOMEM;
@@ -220,6 +220,7 @@ static void tcf_pedit_cleanup(struct tc_action *a)
220220
{
221221
struct tcf_pedit *p = to_pedit(a);
222222
struct tc_pedit_key *keys = p->tcfp_keys;
223+
223224
kfree(keys);
224225
kfree(p->tcfp_keys_ex);
225226
}
@@ -284,11 +285,12 @@ static int tcf_pedit(struct sk_buff *skb, const struct tc_action *a,
284285
if (p->tcfp_nkeys > 0) {
285286
struct tc_pedit_key *tkey = p->tcfp_keys;
286287
struct tcf_pedit_key_ex *tkey_ex = p->tcfp_keys_ex;
287-
enum pedit_header_type htype = TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK;
288+
enum pedit_header_type htype =
289+
TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK;
288290
enum pedit_cmd cmd = TCA_PEDIT_KEY_EX_CMD_SET;
289291

290292
for (i = p->tcfp_nkeys; i > 0; i--, tkey++) {
291-
u32 *ptr, _data;
293+
u32 *ptr, hdata;
292294
int offset = tkey->off;
293295
int hoffset;
294296
u32 val;
@@ -303,39 +305,39 @@ static int tcf_pedit(struct sk_buff *skb, const struct tc_action *a,
303305

304306
rc = pedit_skb_hdr_offset(skb, htype, &hoffset);
305307
if (rc) {
306-
pr_info("tc filter pedit bad header type specified (0x%x)\n",
308+
pr_info("tc action pedit bad header type specified (0x%x)\n",
307309
htype);
308310
goto bad;
309311
}
310312

311313
if (tkey->offmask) {
312-
char *d, _d;
314+
u8 *d, _d;
313315

314316
if (!offset_valid(skb, hoffset + tkey->at)) {
315-
pr_info("tc filter pedit 'at' offset %d out of bounds\n",
317+
pr_info("tc action pedit 'at' offset %d out of bounds\n",
316318
hoffset + tkey->at);
317319
goto bad;
318320
}
319-
d = skb_header_pointer(skb, hoffset + tkey->at, 1,
320-
&_d);
321+
d = skb_header_pointer(skb, hoffset + tkey->at,
322+
sizeof(_d), &_d);
321323
if (!d)
322324
goto bad;
323325
offset += (*d & tkey->offmask) >> tkey->shift;
324326
}
325327

326328
if (offset % 4) {
327-
pr_info("tc filter pedit"
328-
" offset must be on 32 bit boundaries\n");
329+
pr_info("tc action pedit offset must be on 32 bit boundaries\n");
329330
goto bad;
330331
}
331332

332333
if (!offset_valid(skb, hoffset + offset)) {
333-
pr_info("tc filter pedit offset %d out of bounds\n",
334+
pr_info("tc action pedit offset %d out of bounds\n",
334335
hoffset + offset);
335336
goto bad;
336337
}
337338

338-
ptr = skb_header_pointer(skb, hoffset + offset, 4, &_data);
339+
ptr = skb_header_pointer(skb, hoffset + offset,
340+
sizeof(hdata), &hdata);
339341
if (!ptr)
340342
goto bad;
341343
/* just do it, baby */
@@ -347,19 +349,20 @@ static int tcf_pedit(struct sk_buff *skb, const struct tc_action *a,
347349
val = (*ptr + tkey->val) & ~tkey->mask;
348350
break;
349351
default:
350-
pr_info("tc filter pedit bad command (%d)\n",
352+
pr_info("tc action pedit bad command (%d)\n",
351353
cmd);
352354
goto bad;
353355
}
354356

355357
*ptr = ((*ptr & tkey->mask) ^ val);
356-
if (ptr == &_data)
358+
if (ptr == &hdata)
357359
skb_store_bits(skb, hoffset + offset, ptr, 4);
358360
}
359361

360362
goto done;
361-
} else
363+
} else {
362364
WARN(1, "pedit BUG: index %d\n", p->tcf_index);
365+
}
363366

364367
bad:
365368
p->tcf_qstats.overlimits++;

0 commit comments

Comments
 (0)