Skip to content

Commit 2cddd20

Browse files
Ivan Veceradavem330
authored andcommitted
net/sched: cls_flower: allocate mask dynamically in fl_change()
Recent changes (especially 05cd271 ("cls_flower: Support multiple masks per priority")) in the fl_flow_mask structure grow it and its current size e.g. on x86_64 with defconfig is 760 bytes and more than 1024 bytes with some debug options enabled. Prior the mentioned commit its size was 176 bytes (using defconfig on x86_64). With regard to this fact it's reasonable to allocate this structure dynamically in fl_change() to reduce its stack size. v2: - use kzalloc() instead of kcalloc() Fixes: 05cd271 ("cls_flower: Support multiple masks per priority") Cc: Jiri Pirko <jiri@resnulli.us> Cc: Paul Blakey <paulb@mellanox.com> Acked-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: Ivan Vecera <ivecera@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3f1bb6a commit 2cddd20

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

net/sched/cls_flower.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,17 +1290,23 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
12901290
struct cls_fl_head *head = rtnl_dereference(tp->root);
12911291
struct cls_fl_filter *fold = *arg;
12921292
struct cls_fl_filter *fnew;
1293+
struct fl_flow_mask *mask;
12931294
struct nlattr **tb;
1294-
struct fl_flow_mask mask = {};
12951295
int err;
12961296

12971297
if (!tca[TCA_OPTIONS])
12981298
return -EINVAL;
12991299

1300-
tb = kcalloc(TCA_FLOWER_MAX + 1, sizeof(struct nlattr *), GFP_KERNEL);
1301-
if (!tb)
1300+
mask = kzalloc(sizeof(struct fl_flow_mask), GFP_KERNEL);
1301+
if (!mask)
13021302
return -ENOBUFS;
13031303

1304+
tb = kcalloc(TCA_FLOWER_MAX + 1, sizeof(struct nlattr *), GFP_KERNEL);
1305+
if (!tb) {
1306+
err = -ENOBUFS;
1307+
goto errout_mask_alloc;
1308+
}
1309+
13041310
err = nla_parse_nested(tb, TCA_FLOWER_MAX, tca[TCA_OPTIONS],
13051311
fl_policy, NULL);
13061312
if (err < 0)
@@ -1343,12 +1349,12 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
13431349
}
13441350
}
13451351

1346-
err = fl_set_parms(net, tp, fnew, &mask, base, tb, tca[TCA_RATE], ovr,
1352+
err = fl_set_parms(net, tp, fnew, mask, base, tb, tca[TCA_RATE], ovr,
13471353
tp->chain->tmplt_priv, extack);
13481354
if (err)
13491355
goto errout_idr;
13501356

1351-
err = fl_check_assign_mask(head, fnew, fold, &mask);
1357+
err = fl_check_assign_mask(head, fnew, fold, mask);
13521358
if (err)
13531359
goto errout_idr;
13541360

@@ -1392,6 +1398,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
13921398
}
13931399

13941400
kfree(tb);
1401+
kfree(mask);
13951402
return 0;
13961403

13971404
errout_mask:
@@ -1405,6 +1412,8 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
14051412
kfree(fnew);
14061413
errout_tb:
14071414
kfree(tb);
1415+
errout_mask_alloc:
1416+
kfree(mask);
14081417
return err;
14091418
}
14101419

0 commit comments

Comments
 (0)