Skip to content

Commit 8113c09

Browse files
congwangdavem330
authored andcommitted
net_sched: use void pointer for filter handle
Now we use 'unsigned long fh' as a pointer in every place, it is safe to convert it to a void pointer now. This gets rid of many casts to pointer. Cc: Jamal Hadi Salim <[email protected]> Cc: Jiri Pirko <[email protected]> Signed-off-by: Cong Wang <[email protected]> Acked-by: Jamal Hadi Salim <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 54df2cf commit 8113c09

File tree

14 files changed

+141
-151
lines changed

14 files changed

+141
-151
lines changed

include/net/pkt_cls.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct tcf_walker {
1111
int stop;
1212
int skip;
1313
int count;
14-
int (*fn)(struct tcf_proto *, unsigned long node, struct tcf_walker *);
14+
int (*fn)(struct tcf_proto *, void *node, struct tcf_walker *);
1515
};
1616

1717
int register_tcf_proto_ops(struct tcf_proto_ops *ops);

include/net/sch_generic.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,16 @@ struct tcf_proto_ops {
213213
int (*init)(struct tcf_proto*);
214214
void (*destroy)(struct tcf_proto*);
215215

216-
unsigned long (*get)(struct tcf_proto*, u32 handle);
216+
void* (*get)(struct tcf_proto*, u32 handle);
217217
int (*change)(struct net *net, struct sk_buff *,
218218
struct tcf_proto*, unsigned long,
219219
u32 handle, struct nlattr **,
220-
unsigned long *, bool);
221-
int (*delete)(struct tcf_proto*, unsigned long, bool*);
220+
void **, bool);
221+
int (*delete)(struct tcf_proto*, void *, bool*);
222222
void (*walk)(struct tcf_proto*, struct tcf_walker *arg);
223223

224224
/* rtnetlink specific */
225-
int (*dump)(struct net*, struct tcf_proto*, unsigned long,
225+
int (*dump)(struct net*, struct tcf_proto*, void *,
226226
struct sk_buff *skb, struct tcmsg*);
227227

228228
struct module *owner;

net/sched/cls_api.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ EXPORT_SYMBOL(unregister_tcf_proto_ops);
102102

103103
static int tfilter_notify(struct net *net, struct sk_buff *oskb,
104104
struct nlmsghdr *n, struct tcf_proto *tp,
105-
unsigned long fh, int event, bool unicast);
105+
void *fh, int event, bool unicast);
106106

107107
static int tfilter_del_notify(struct net *net, struct sk_buff *oskb,
108108
struct nlmsghdr *n, struct tcf_proto *tp,
109-
unsigned long fh, bool unicast, bool *last);
109+
void *fh, bool unicast, bool *last);
110110

111111
static void tfilter_notify_chain(struct net *net, struct sk_buff *oskb,
112112
struct nlmsghdr *n,
@@ -432,7 +432,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
432432
struct tcf_proto *tp;
433433
const struct Qdisc_class_ops *cops;
434434
unsigned long cl;
435-
unsigned long fh;
435+
void *fh;
436436
int err;
437437
int tp_created;
438438

@@ -571,7 +571,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
571571

572572
fh = tp->ops->get(tp, t->tcm_handle);
573573

574-
if (fh == 0) {
574+
if (!fh) {
575575
if (n->nlmsg_type == RTM_DELTFILTER && t->tcm_handle == 0) {
576576
tcf_chain_tp_remove(chain, &chain_info, tp);
577577
tfilter_notify(net, skb, n, tp, fh,
@@ -641,7 +641,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
641641
}
642642

643643
static int tcf_fill_node(struct net *net, struct sk_buff *skb,
644-
struct tcf_proto *tp, unsigned long fh, u32 portid,
644+
struct tcf_proto *tp, void *fh, u32 portid,
645645
u32 seq, u16 flags, int event)
646646
{
647647
struct tcmsg *tcm;
@@ -679,7 +679,7 @@ static int tcf_fill_node(struct net *net, struct sk_buff *skb,
679679

680680
static int tfilter_notify(struct net *net, struct sk_buff *oskb,
681681
struct nlmsghdr *n, struct tcf_proto *tp,
682-
unsigned long fh, int event, bool unicast)
682+
void *fh, int event, bool unicast)
683683
{
684684
struct sk_buff *skb;
685685
u32 portid = oskb ? NETLINK_CB(oskb).portid : 0;
@@ -703,7 +703,7 @@ static int tfilter_notify(struct net *net, struct sk_buff *oskb,
703703

704704
static int tfilter_del_notify(struct net *net, struct sk_buff *oskb,
705705
struct nlmsghdr *n, struct tcf_proto *tp,
706-
unsigned long fh, bool unicast, bool *last)
706+
void *fh, bool unicast, bool *last)
707707
{
708708
struct sk_buff *skb;
709709
u32 portid = oskb ? NETLINK_CB(oskb).portid : 0;
@@ -738,8 +738,7 @@ struct tcf_dump_args {
738738
struct netlink_callback *cb;
739739
};
740740

741-
static int tcf_node_dump(struct tcf_proto *tp, unsigned long n,
742-
struct tcf_walker *arg)
741+
static int tcf_node_dump(struct tcf_proto *tp, void *n, struct tcf_walker *arg)
743742
{
744743
struct tcf_dump_args *a = (void *)arg;
745744
struct net *net = sock_net(a->skb->sk);

net/sched/cls_basic.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,18 @@ static int basic_classify(struct sk_buff *skb, const struct tcf_proto *tp,
5656
return -1;
5757
}
5858

59-
static unsigned long basic_get(struct tcf_proto *tp, u32 handle)
59+
static void *basic_get(struct tcf_proto *tp, u32 handle)
6060
{
61-
unsigned long l = 0UL;
6261
struct basic_head *head = rtnl_dereference(tp->root);
6362
struct basic_filter *f;
6463

6564
list_for_each_entry(f, &head->flist, link) {
6665
if (f->handle == handle) {
67-
l = (unsigned long) f;
68-
break;
66+
return f;
6967
}
7068
}
7169

72-
return l;
70+
return NULL;
7371
}
7472

7573
static int basic_init(struct tcf_proto *tp)
@@ -106,10 +104,10 @@ static void basic_destroy(struct tcf_proto *tp)
106104
kfree_rcu(head, rcu);
107105
}
108106

109-
static int basic_delete(struct tcf_proto *tp, unsigned long arg, bool *last)
107+
static int basic_delete(struct tcf_proto *tp, void *arg, bool *last)
110108
{
111109
struct basic_head *head = rtnl_dereference(tp->root);
112-
struct basic_filter *f = (struct basic_filter *) arg;
110+
struct basic_filter *f = arg;
113111

114112
list_del_rcu(&f->link);
115113
tcf_unbind_filter(tp, &f->res);
@@ -149,7 +147,7 @@ static int basic_set_parms(struct net *net, struct tcf_proto *tp,
149147

150148
static int basic_change(struct net *net, struct sk_buff *in_skb,
151149
struct tcf_proto *tp, unsigned long base, u32 handle,
152-
struct nlattr **tca, unsigned long *arg, bool ovr)
150+
struct nlattr **tca, void **arg, bool ovr)
153151
{
154152
int err;
155153
struct basic_head *head = rtnl_dereference(tp->root);
@@ -202,7 +200,7 @@ static int basic_change(struct net *net, struct sk_buff *in_skb,
202200
if (err < 0)
203201
goto errout;
204202

205-
*arg = (unsigned long)fnew;
203+
*arg = fnew;
206204

207205
if (fold) {
208206
list_replace_rcu(&fold->link, &fnew->link);
@@ -228,7 +226,7 @@ static void basic_walk(struct tcf_proto *tp, struct tcf_walker *arg)
228226
if (arg->count < arg->skip)
229227
goto skip;
230228

231-
if (arg->fn(tp, (unsigned long) f, arg) < 0) {
229+
if (arg->fn(tp, f, arg) < 0) {
232230
arg->stop = 1;
233231
break;
234232
}
@@ -237,10 +235,10 @@ static void basic_walk(struct tcf_proto *tp, struct tcf_walker *arg)
237235
}
238236
}
239237

240-
static int basic_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,
238+
static int basic_dump(struct net *net, struct tcf_proto *tp, void *fh,
241239
struct sk_buff *skb, struct tcmsg *t)
242240
{
243-
struct basic_filter *f = (struct basic_filter *) fh;
241+
struct basic_filter *f = fh;
244242
struct nlattr *nest;
245243

246244
if (f == NULL)

net/sched/cls_bpf.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,11 @@ static void __cls_bpf_delete(struct tcf_proto *tp, struct cls_bpf_prog *prog)
270270
call_rcu(&prog->rcu, cls_bpf_delete_prog_rcu);
271271
}
272272

273-
static int cls_bpf_delete(struct tcf_proto *tp, unsigned long arg, bool *last)
273+
static int cls_bpf_delete(struct tcf_proto *tp, void *arg, bool *last)
274274
{
275275
struct cls_bpf_head *head = rtnl_dereference(tp->root);
276276

277-
__cls_bpf_delete(tp, (struct cls_bpf_prog *) arg);
277+
__cls_bpf_delete(tp, arg);
278278
*last = list_empty(&head->plist);
279279
return 0;
280280
}
@@ -290,20 +290,17 @@ static void cls_bpf_destroy(struct tcf_proto *tp)
290290
kfree_rcu(head, rcu);
291291
}
292292

293-
static unsigned long cls_bpf_get(struct tcf_proto *tp, u32 handle)
293+
static void *cls_bpf_get(struct tcf_proto *tp, u32 handle)
294294
{
295295
struct cls_bpf_head *head = rtnl_dereference(tp->root);
296296
struct cls_bpf_prog *prog;
297-
unsigned long ret = 0UL;
298297

299298
list_for_each_entry(prog, &head->plist, link) {
300-
if (prog->handle == handle) {
301-
ret = (unsigned long) prog;
302-
break;
303-
}
299+
if (prog->handle == handle)
300+
return prog;
304301
}
305302

306-
return ret;
303+
return NULL;
307304
}
308305

309306
static int cls_bpf_prog_from_ops(struct nlattr **tb, struct cls_bpf_prog *prog)
@@ -448,10 +445,10 @@ static u32 cls_bpf_grab_new_handle(struct tcf_proto *tp,
448445
static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
449446
struct tcf_proto *tp, unsigned long base,
450447
u32 handle, struct nlattr **tca,
451-
unsigned long *arg, bool ovr)
448+
void **arg, bool ovr)
452449
{
453450
struct cls_bpf_head *head = rtnl_dereference(tp->root);
454-
struct cls_bpf_prog *oldprog = (struct cls_bpf_prog *) *arg;
451+
struct cls_bpf_prog *oldprog = *arg;
455452
struct nlattr *tb[TCA_BPF_MAX + 1];
456453
struct cls_bpf_prog *prog;
457454
int ret;
@@ -509,7 +506,7 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
509506
list_add_rcu(&prog->link, &head->plist);
510507
}
511508

512-
*arg = (unsigned long) prog;
509+
*arg = prog;
513510
return 0;
514511

515512
errout:
@@ -557,10 +554,10 @@ static int cls_bpf_dump_ebpf_info(const struct cls_bpf_prog *prog,
557554
return 0;
558555
}
559556

560-
static int cls_bpf_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,
557+
static int cls_bpf_dump(struct net *net, struct tcf_proto *tp, void *fh,
561558
struct sk_buff *skb, struct tcmsg *tm)
562559
{
563-
struct cls_bpf_prog *prog = (struct cls_bpf_prog *) fh;
560+
struct cls_bpf_prog *prog = fh;
564561
struct nlattr *nest;
565562
u32 bpf_flags = 0;
566563
int ret;
@@ -618,7 +615,7 @@ static void cls_bpf_walk(struct tcf_proto *tp, struct tcf_walker *arg)
618615
list_for_each_entry(prog, &head->plist, link) {
619616
if (arg->count < arg->skip)
620617
goto skip;
621-
if (arg->fn(tp, (unsigned long) prog, arg) < 0) {
618+
if (arg->fn(tp, prog, arg) < 0) {
622619
arg->stop = 1;
623620
break;
624621
}

net/sched/cls_cgroup.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ static int cls_cgroup_classify(struct sk_buff *skb, const struct tcf_proto *tp,
4343
return tcf_exts_exec(skb, &head->exts, res);
4444
}
4545

46-
static unsigned long cls_cgroup_get(struct tcf_proto *tp, u32 handle)
46+
static void *cls_cgroup_get(struct tcf_proto *tp, u32 handle)
4747
{
48-
return 0UL;
48+
return NULL;
4949
}
5050

5151
static int cls_cgroup_init(struct tcf_proto *tp)
@@ -71,7 +71,7 @@ static void cls_cgroup_destroy_rcu(struct rcu_head *root)
7171
static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,
7272
struct tcf_proto *tp, unsigned long base,
7373
u32 handle, struct nlattr **tca,
74-
unsigned long *arg, bool ovr)
74+
void **arg, bool ovr)
7575
{
7676
struct nlattr *tb[TCA_CGROUP_MAX + 1];
7777
struct cls_cgroup_head *head = rtnl_dereference(tp->root);
@@ -128,7 +128,7 @@ static void cls_cgroup_destroy(struct tcf_proto *tp)
128128
call_rcu(&head->rcu, cls_cgroup_destroy_rcu);
129129
}
130130

131-
static int cls_cgroup_delete(struct tcf_proto *tp, unsigned long arg, bool *last)
131+
static int cls_cgroup_delete(struct tcf_proto *tp, void *arg, bool *last)
132132
{
133133
return -EOPNOTSUPP;
134134
}
@@ -140,15 +140,15 @@ static void cls_cgroup_walk(struct tcf_proto *tp, struct tcf_walker *arg)
140140
if (arg->count < arg->skip)
141141
goto skip;
142142

143-
if (arg->fn(tp, (unsigned long) head, arg) < 0) {
143+
if (arg->fn(tp, head, arg) < 0) {
144144
arg->stop = 1;
145145
return;
146146
}
147147
skip:
148148
arg->count++;
149149
}
150150

151-
static int cls_cgroup_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,
151+
static int cls_cgroup_dump(struct net *net, struct tcf_proto *tp, void *fh,
152152
struct sk_buff *skb, struct tcmsg *t)
153153
{
154154
struct cls_cgroup_head *head = rtnl_dereference(tp->root);

net/sched/cls_flow.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ static void flow_destroy_filter(struct rcu_head *head)
382382
static int flow_change(struct net *net, struct sk_buff *in_skb,
383383
struct tcf_proto *tp, unsigned long base,
384384
u32 handle, struct nlattr **tca,
385-
unsigned long *arg, bool ovr)
385+
void **arg, bool ovr)
386386
{
387387
struct flow_head *head = rtnl_dereference(tp->root);
388388
struct flow_filter *fold, *fnew;
@@ -439,7 +439,7 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,
439439
if (err < 0)
440440
goto err2;
441441

442-
fold = (struct flow_filter *)*arg;
442+
fold = *arg;
443443
if (fold) {
444444
err = -EINVAL;
445445
if (fold->handle != handle && handle)
@@ -532,12 +532,12 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,
532532
if (perturb_period)
533533
mod_timer(&fnew->perturb_timer, jiffies + perturb_period);
534534

535-
if (*arg == 0)
535+
if (!*arg)
536536
list_add_tail_rcu(&fnew->list, &head->filters);
537537
else
538538
list_replace_rcu(&fold->list, &fnew->list);
539539

540-
*arg = (unsigned long)fnew;
540+
*arg = fnew;
541541

542542
if (fold)
543543
call_rcu(&fold->rcu, flow_destroy_filter);
@@ -551,10 +551,10 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,
551551
return err;
552552
}
553553

554-
static int flow_delete(struct tcf_proto *tp, unsigned long arg, bool *last)
554+
static int flow_delete(struct tcf_proto *tp, void *arg, bool *last)
555555
{
556556
struct flow_head *head = rtnl_dereference(tp->root);
557-
struct flow_filter *f = (struct flow_filter *)arg;
557+
struct flow_filter *f = arg;
558558

559559
list_del_rcu(&f->list);
560560
call_rcu(&f->rcu, flow_destroy_filter);
@@ -586,21 +586,21 @@ static void flow_destroy(struct tcf_proto *tp)
586586
kfree_rcu(head, rcu);
587587
}
588588

589-
static unsigned long flow_get(struct tcf_proto *tp, u32 handle)
589+
static void *flow_get(struct tcf_proto *tp, u32 handle)
590590
{
591591
struct flow_head *head = rtnl_dereference(tp->root);
592592
struct flow_filter *f;
593593

594594
list_for_each_entry(f, &head->filters, list)
595595
if (f->handle == handle)
596-
return (unsigned long)f;
597-
return 0;
596+
return f;
597+
return NULL;
598598
}
599599

600-
static int flow_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,
600+
static int flow_dump(struct net *net, struct tcf_proto *tp, void *fh,
601601
struct sk_buff *skb, struct tcmsg *t)
602602
{
603-
struct flow_filter *f = (struct flow_filter *)fh;
603+
struct flow_filter *f = fh;
604604
struct nlattr *nest;
605605

606606
if (f == NULL)
@@ -666,7 +666,7 @@ static void flow_walk(struct tcf_proto *tp, struct tcf_walker *arg)
666666
list_for_each_entry(f, &head->filters, list) {
667667
if (arg->count < arg->skip)
668668
goto skip;
669-
if (arg->fn(tp, (unsigned long)f, arg) < 0) {
669+
if (arg->fn(tp, f, arg) < 0) {
670670
arg->stop = 1;
671671
break;
672672
}

0 commit comments

Comments
 (0)