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

net: sched: sch_red: Split init and change callbacks

In the following patches, RED will get two qevents. The implementation will
be clearer if the callback for change is not a pure subset of the callback
for init. Split the two and promote attribute parsing to the callbacks
themselves from the common code, because it will be handy there.

Signed-off-by: Petr Machata <petrm@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Petr Machata and committed by
David S. Miller
65545ea2 3625750f

+30 -12
+30 -12
net/sched/sch_red.c
··· 215 215 [TCA_RED_FLAGS] = NLA_POLICY_BITFIELD32(TC_RED_SUPPORTED_FLAGS), 216 216 }; 217 217 218 - static int red_change(struct Qdisc *sch, struct nlattr *opt, 219 - struct netlink_ext_ack *extack) 218 + static int __red_change(struct Qdisc *sch, struct nlattr **tb, 219 + struct netlink_ext_ack *extack) 220 220 { 221 221 struct Qdisc *old_child = NULL, *child = NULL; 222 222 struct red_sched_data *q = qdisc_priv(sch); 223 - struct nlattr *tb[TCA_RED_MAX + 1]; 224 223 struct nla_bitfield32 flags_bf; 225 224 struct tc_red_qopt *ctl; 226 225 unsigned char userbits; 227 226 unsigned char flags; 228 227 int err; 229 228 u32 max_P; 230 - 231 - if (opt == NULL) 232 - return -EINVAL; 233 - 234 - err = nla_parse_nested_deprecated(tb, TCA_RED_MAX, opt, red_policy, 235 - NULL); 236 - if (err < 0) 237 - return err; 238 229 239 230 if (tb[TCA_RED_PARMS] == NULL || 240 231 tb[TCA_RED_STAB] == NULL) ··· 314 323 struct netlink_ext_ack *extack) 315 324 { 316 325 struct red_sched_data *q = qdisc_priv(sch); 326 + struct nlattr *tb[TCA_RED_MAX + 1]; 327 + int err; 328 + 329 + if (!opt) 330 + return -EINVAL; 331 + 332 + err = nla_parse_nested_deprecated(tb, TCA_RED_MAX, opt, red_policy, 333 + extack); 334 + if (err < 0) 335 + return err; 317 336 318 337 q->qdisc = &noop_qdisc; 319 338 q->sch = sch; 320 339 timer_setup(&q->adapt_timer, red_adaptative_timer, 0); 321 - return red_change(sch, opt, extack); 340 + return __red_change(sch, tb, extack); 341 + } 342 + 343 + static int red_change(struct Qdisc *sch, struct nlattr *opt, 344 + struct netlink_ext_ack *extack) 345 + { 346 + struct nlattr *tb[TCA_RED_MAX + 1]; 347 + int err; 348 + 349 + if (!opt) 350 + return -EINVAL; 351 + 352 + err = nla_parse_nested_deprecated(tb, TCA_RED_MAX, opt, red_policy, 353 + extack); 354 + if (err < 0) 355 + return err; 356 + 357 + return __red_change(sch, tb, extack); 322 358 } 323 359 324 360 static int red_dump_offload_stats(struct Qdisc *sch)