Skip to content

Commit 54160ef

Browse files
Alexander Aringdavem330
authored andcommitted
net: sched: sch_api: rearrange init handling
This patch fixes the following checkpatch error: ERROR: do not use assignment in if condition by rearranging the if condition to execute init callback only if init callback exists. The whole setup afterwards is called in any case, doesn't matter if init callback is set or not. This patch has the same behaviour as before, just without assign err variable in if condition. It also makes the code easier to read. Reviewed-by: Jamal Hadi Salim <[email protected]> Cc: David Ahern <[email protected]> Signed-off-by: Alexander Aring <[email protected]> Acked-by: Jamal Hadi Salim <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0ac4bd6 commit 54160ef

File tree

1 file changed

+47
-41
lines changed

1 file changed

+47
-41
lines changed

net/sched/sch_api.c

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,54 +1060,60 @@ static struct Qdisc *qdisc_create(struct net_device *dev,
10601060
netdev_info(dev, "Caught tx_queue_len zero misconfig\n");
10611061
}
10621062

1063-
if (!ops->init || (err = ops->init(sch, tca[TCA_OPTIONS])) == 0) {
1064-
if (qdisc_is_percpu_stats(sch)) {
1065-
sch->cpu_bstats =
1066-
netdev_alloc_pcpu_stats(struct gnet_stats_basic_cpu);
1067-
if (!sch->cpu_bstats)
1068-
goto err_out4;
1069-
1070-
sch->cpu_qstats = alloc_percpu(struct gnet_stats_queue);
1071-
if (!sch->cpu_qstats)
1072-
goto err_out4;
1073-
}
1063+
if (ops->init) {
1064+
err = ops->init(sch, tca[TCA_OPTIONS]);
1065+
if (err != 0)
1066+
goto err_out5;
1067+
}
10741068

1075-
if (tca[TCA_STAB]) {
1076-
stab = qdisc_get_stab(tca[TCA_STAB]);
1077-
if (IS_ERR(stab)) {
1078-
err = PTR_ERR(stab);
1079-
goto err_out4;
1080-
}
1081-
rcu_assign_pointer(sch->stab, stab);
1082-
}
1083-
if (tca[TCA_RATE]) {
1084-
seqcount_t *running;
1069+
if (qdisc_is_percpu_stats(sch)) {
1070+
sch->cpu_bstats =
1071+
netdev_alloc_pcpu_stats(struct gnet_stats_basic_cpu);
1072+
if (!sch->cpu_bstats)
1073+
goto err_out4;
10851074

1086-
err = -EOPNOTSUPP;
1087-
if (sch->flags & TCQ_F_MQROOT)
1088-
goto err_out4;
1075+
sch->cpu_qstats = alloc_percpu(struct gnet_stats_queue);
1076+
if (!sch->cpu_qstats)
1077+
goto err_out4;
1078+
}
10891079

1090-
if (sch->parent != TC_H_ROOT &&
1091-
!(sch->flags & TCQ_F_INGRESS) &&
1092-
(!p || !(p->flags & TCQ_F_MQROOT)))
1093-
running = qdisc_root_sleeping_running(sch);
1094-
else
1095-
running = &sch->running;
1096-
1097-
err = gen_new_estimator(&sch->bstats,
1098-
sch->cpu_bstats,
1099-
&sch->rate_est,
1100-
NULL,
1101-
running,
1102-
tca[TCA_RATE]);
1103-
if (err)
1104-
goto err_out4;
1080+
if (tca[TCA_STAB]) {
1081+
stab = qdisc_get_stab(tca[TCA_STAB]);
1082+
if (IS_ERR(stab)) {
1083+
err = PTR_ERR(stab);
1084+
goto err_out4;
11051085
}
1086+
rcu_assign_pointer(sch->stab, stab);
1087+
}
1088+
if (tca[TCA_RATE]) {
1089+
seqcount_t *running;
11061090

1107-
qdisc_hash_add(sch, false);
1091+
err = -EOPNOTSUPP;
1092+
if (sch->flags & TCQ_F_MQROOT)
1093+
goto err_out4;
11081094

1109-
return sch;
1095+
if (sch->parent != TC_H_ROOT &&
1096+
!(sch->flags & TCQ_F_INGRESS) &&
1097+
(!p || !(p->flags & TCQ_F_MQROOT)))
1098+
running = qdisc_root_sleeping_running(sch);
1099+
else
1100+
running = &sch->running;
1101+
1102+
err = gen_new_estimator(&sch->bstats,
1103+
sch->cpu_bstats,
1104+
&sch->rate_est,
1105+
NULL,
1106+
running,
1107+
tca[TCA_RATE]);
1108+
if (err)
1109+
goto err_out4;
11101110
}
1111+
1112+
qdisc_hash_add(sch, false);
1113+
1114+
return sch;
1115+
1116+
err_out5:
11111117
/* ops->init() failed, we call ->destroy() like qdisc_create_dflt() */
11121118
if (ops->destroy)
11131119
ops->destroy(sch);

0 commit comments

Comments
 (0)