]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/net/pktsched/pktsched_tcq.c
xnu-4903.270.47.tar.gz
[apple/xnu.git] / bsd / net / pktsched / pktsched_tcq.c
index 01a6c7cc927db580f77b29d601e345b9c58dc534..d59bf0d5e4016dd1ac3c18ab6031d2756a699269 100644 (file)
@@ -77,22 +77,22 @@ static void tcq_dequeue_cl(struct tcq_if *, struct tcq_class *,
 static inline struct tcq_class *tcq_clh_to_clp(struct tcq_if *, u_int32_t);
 static const char *tcq_style(struct tcq_if *);
 
-#define        TCQ_ZONE_MAX    32              /* maximum elements in zone */
-#define        TCQ_ZONE_NAME   "pktsched_tcq"  /* zone name */
+#define TCQ_ZONE_MAX    32              /* maximum elements in zone */
+#define TCQ_ZONE_NAME   "pktsched_tcq"  /* zone name */
 
-static unsigned int tcq_size;          /* size of zone element */
-static struct zone *tcq_zone;          /* zone for tcq */
+static unsigned int tcq_size;           /* size of zone element */
+static struct zone *tcq_zone;           /* zone for tcq */
 
-#define        TCQ_CL_ZONE_MAX 32              /* maximum elements in zone */
-#define        TCQ_CL_ZONE_NAME "pktsched_tcq_cl" /* zone name */
+#define TCQ_CL_ZONE_MAX 32              /* maximum elements in zone */
+#define TCQ_CL_ZONE_NAME "pktsched_tcq_cl" /* zone name */
 
-static unsigned int tcq_cl_size;       /* size of zone element */
-static struct zone *tcq_cl_zone;       /* zone for tcq_class */
+static unsigned int tcq_cl_size;        /* size of zone element */
+static struct zone *tcq_cl_zone;        /* zone for tcq_class */
 
 void
 tcq_init(void)
 {
-       tcq_size = sizeof (struct tcq_if);
+       tcq_size = sizeof(struct tcq_if);
        tcq_zone = zinit(tcq_size, TCQ_ZONE_MAX * tcq_size,
            0, TCQ_ZONE_NAME);
        if (tcq_zone == NULL) {
@@ -102,7 +102,7 @@ tcq_init(void)
        zone_change(tcq_zone, Z_EXPAND, TRUE);
        zone_change(tcq_zone, Z_CALLERACCT, TRUE);
 
-       tcq_cl_size = sizeof (struct tcq_class);
+       tcq_cl_size = sizeof(struct tcq_class);
        tcq_cl_zone = zinit(tcq_cl_size, TCQ_CL_ZONE_MAX * tcq_cl_size,
            0, TCQ_CL_ZONE_NAME);
        if (tcq_cl_zone == NULL) {
@@ -116,11 +116,12 @@ tcq_init(void)
 struct tcq_if *
 tcq_alloc(struct ifnet *ifp, int how)
 {
-       struct tcq_if   *tif;
+       struct tcq_if   *tif;
 
        tif = (how == M_WAITOK) ? zalloc(tcq_zone) : zalloc_noblock(tcq_zone);
-       if (tif == NULL)
-               return (NULL);
+       if (tif == NULL) {
+               return NULL;
+       }
 
        bzero(tif, tcq_size);
        tif->tif_maxpri = -1;
@@ -131,7 +132,7 @@ tcq_alloc(struct ifnet *ifp, int how)
                    if_name(ifp), tcq_style(tif));
        }
 
-       return (tif);
+       return tif;
 }
 
 int
@@ -144,7 +145,7 @@ tcq_destroy(struct tcq_if *tif)
        err = tcq_destroy_locked(tif);
        IFCQ_UNLOCK(ifq);
 
-       return (err);
+       return err;
 }
 
 static int
@@ -161,7 +162,7 @@ tcq_destroy_locked(struct tcq_if *tif)
 
        zfree(tcq_zone, tif);
 
-       return (0);
+       return 0;
 }
 
 /*
@@ -171,17 +172,19 @@ tcq_destroy_locked(struct tcq_if *tif)
 static int
 tcq_clear_interface(struct tcq_if *tif)
 {
-       struct tcq_class        *cl;
+       struct tcq_class        *cl;
        int pri;
 
        IFCQ_LOCK_ASSERT_HELD(tif->tif_ifq);
 
        /* clear out the classes */
-       for (pri = 0; pri <= tif->tif_maxpri; pri++)
-               if ((cl = tif->tif_classes[pri]) != NULL)
+       for (pri = 0; pri <= tif->tif_maxpri; pri++) {
+               if ((cl = tif->tif_classes[pri]) != NULL) {
                        tcq_class_destroy(tif, cl);
+               }
+       }
 
-       return (0);
+       return 0;
 }
 
 /* discard all the queued packets on the interface */
@@ -194,8 +197,9 @@ tcq_purge(struct tcq_if *tif)
        IFCQ_LOCK_ASSERT_HELD(tif->tif_ifq);
 
        for (pri = 0; pri <= tif->tif_maxpri; pri++) {
-               if ((cl = tif->tif_classes[pri]) != NULL && !qempty(&cl->cl_q))
+               if ((cl = tif->tif_classes[pri]) != NULL && !qempty(&cl->cl_q)) {
                        tcq_purgeq(tif, cl, 0, NULL, NULL);
+               }
        }
        VERIFY(IFCQ_LEN(tif->tif_ifq) == 0);
 }
@@ -240,9 +244,11 @@ tcq_event(struct tcq_if *tif, cqev_t ev)
 
        IFCQ_LOCK_ASSERT_HELD(tif->tif_ifq);
 
-       for (pri = 0; pri <= tif->tif_maxpri; pri++)
-               if ((cl = tif->tif_classes[pri]) != NULL)
+       for (pri = 0; pri <= tif->tif_maxpri; pri++) {
+               if ((cl = tif->tif_classes[pri]) != NULL) {
                        tcq_updateq(tif, cl, ev);
+               }
+       }
 }
 
 int
@@ -254,21 +260,26 @@ tcq_add_queue(struct tcq_if *tif, int priority, u_int32_t qlimit,
        IFCQ_LOCK_ASSERT_HELD(tif->tif_ifq);
 
        /* check parameters */
-       if (priority >= TCQ_MAXPRI)
-               return (EINVAL);
-       if (tif->tif_classes[priority] != NULL)
-               return (EBUSY);
-       if (tcq_clh_to_clp(tif, qid) != NULL)
-               return (EBUSY);
+       if (priority >= TCQ_MAXPRI) {
+               return EINVAL;
+       }
+       if (tif->tif_classes[priority] != NULL) {
+               return EBUSY;
+       }
+       if (tcq_clh_to_clp(tif, qid) != NULL) {
+               return EBUSY;
+       }
 
        cl = tcq_class_create(tif, priority, qlimit, flags, qid, ptype);
-       if (cl == NULL)
-               return (ENOMEM);
+       if (cl == NULL) {
+               return ENOMEM;
+       }
 
-       if (clp != NULL)
+       if (clp != NULL) {
                *clp = cl;
+       }
 
-       return (0);
+       return 0;
 }
 
 static struct tcq_class *
@@ -286,36 +297,42 @@ tcq_class_create(struct tcq_if *tif, int pri, u_int32_t qlimit,
 
        if ((cl = tif->tif_classes[pri]) != NULL) {
                /* modify the class instead of creating a new one */
-               if (!qempty(&cl->cl_q))
+               if (!qempty(&cl->cl_q)) {
                        tcq_purgeq(tif, cl, 0, NULL, NULL);
+               }
 
-               if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL)
+               if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL) {
                        sfb_destroy(cl->cl_sfb);
+               }
                cl->cl_qalg.ptr = NULL;
                qtype(&cl->cl_q) = Q_DROPTAIL;
                qstate(&cl->cl_q) = QS_RUNNING;
                VERIFY(qptype(&cl->cl_q) == ptype);
        } else {
                cl = zalloc(tcq_cl_zone);
-               if (cl == NULL)
-                       return (NULL);
+               if (cl == NULL) {
+                       return NULL;
+               }
 
                bzero(cl, tcq_cl_size);
        }
 
        tif->tif_classes[pri] = cl;
-       if (flags & TQCF_DEFAULTCLASS)
+       if (flags & TQCF_DEFAULTCLASS) {
                tif->tif_default = cl;
+       }
        if (qlimit == 0 || qlimit > IFCQ_MAXLEN(ifq)) {
                qlimit = IFCQ_MAXLEN(ifq);
-               if (qlimit == 0)
+               if (qlimit == 0) {
                        qlimit = DEFAULT_QLIMIT;  /* use default */
+               }
        }
        _qinit(&cl->cl_q, Q_DROPTAIL, qlimit, ptype);
        cl->cl_flags = flags;
        cl->cl_pri = pri;
-       if (pri > tif->tif_maxpri)
+       if (pri > tif->tif_maxpri) {
                tif->tif_maxpri = pri;
+       }
        cl->cl_tif = tif;
        cl->cl_handle = qid;
 
@@ -330,11 +347,13 @@ tcq_class_create(struct tcq_if *tif, int pri, u_int32_t qlimit,
                if (flags & TQCF_DELAYBASED) {
                        cl->cl_qflags |= SFBF_DELAYBASED;
                }
-               if (!(cl->cl_flags & TQCF_LAZY))
+               if (!(cl->cl_flags & TQCF_LAZY)) {
                        cl->cl_sfb = sfb_alloc(ifp, cl->cl_handle,
                            qlimit(&cl->cl_q), cl->cl_qflags);
-               if (cl->cl_sfb != NULL || (cl->cl_flags & TQCF_LAZY))
+               }
+               if (cl->cl_sfb != NULL || (cl->cl_flags & TQCF_LAZY)) {
                        qtype(&cl->cl_q) = Q_SFB;
+               }
        }
 
        if (pktsched_verbose) {
@@ -343,7 +362,7 @@ tcq_class_create(struct tcq_if *tif, int pri, u_int32_t qlimit,
                    cl->cl_handle, cl->cl_pri, qlimit, flags, TQCF_BITS);
        }
 
-       return (cl);
+       return cl;
 }
 
 int
@@ -353,10 +372,11 @@ tcq_remove_queue(struct tcq_if *tif, u_int32_t qid)
 
        IFCQ_LOCK_ASSERT_HELD(tif->tif_ifq);
 
-       if ((cl = tcq_clh_to_clp(tif, qid)) == NULL)
-               return (EINVAL);
+       if ((cl = tcq_clh_to_clp(tif, qid)) == NULL) {
+               return EINVAL;
+       }
 
-       return (tcq_class_destroy(tif, cl));
+       return tcq_class_destroy(tif, cl);
 }
 
 static int
@@ -369,26 +389,31 @@ tcq_class_destroy(struct tcq_if *tif, struct tcq_class *cl)
 #endif
        IFCQ_LOCK_ASSERT_HELD(ifq);
 
-       if (!qempty(&cl->cl_q))
+       if (!qempty(&cl->cl_q)) {
                tcq_purgeq(tif, cl, 0, NULL, NULL);
+       }
 
        tif->tif_classes[cl->cl_pri] = NULL;
        if (tif->tif_maxpri == cl->cl_pri) {
-               for (pri = cl->cl_pri; pri >= 0; pri--)
+               for (pri = cl->cl_pri; pri >= 0; pri--) {
                        if (tif->tif_classes[pri] != NULL) {
                                tif->tif_maxpri = pri;
                                break;
                        }
-               if (pri < 0)
+               }
+               if (pri < 0) {
                        tif->tif_maxpri = -1;
+               }
        }
 
-       if (tif->tif_default == cl)
+       if (tif->tif_default == cl) {
                tif->tif_default = NULL;
+       }
 
        if (cl->cl_qalg.ptr != NULL) {
-               if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL)
+               if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL) {
                        sfb_destroy(cl->cl_sfb);
+               }
                cl->cl_qalg.ptr = NULL;
                qtype(&cl->cl_q) = Q_DROPTAIL;
                qstate(&cl->cl_q) = QS_RUNNING;
@@ -401,7 +426,7 @@ tcq_class_destroy(struct tcq_if *tif, struct tcq_class *cl)
        }
 
        zfree(tcq_cl_zone, cl);
-       return (0);
+       return 0;
 }
 
 int
@@ -420,7 +445,7 @@ tcq_enqueue(struct tcq_if *tif, struct tcq_class *cl, pktsched_pkt_t *pkt,
                        cl = tif->tif_default;
                        if (cl == NULL) {
                                IFCQ_CONVERT_LOCK(ifq);
-                               return (CLASSQEQ_DROP);
+                               return CLASSQEQ_DROP;
                        }
                }
        }
@@ -435,13 +460,13 @@ tcq_enqueue(struct tcq_if *tif, struct tcq_class *cl, pktsched_pkt_t *pkt,
                    ret == CLASSQEQ_DROP_SP);
                PKTCNTR_ADD(&cl->cl_dropcnt, 1, len);
                IFCQ_DROP_ADD(ifq, 1, len);
-               return (ret);
+               return ret;
        }
        IFCQ_INC_LEN(ifq);
        IFCQ_INC_BYTES(ifq, len);
 
        /* successfully queued. */
-       return (ret);
+       return ret;
 }
 
 /*
@@ -485,8 +510,9 @@ tcq_dequeue_cl(struct tcq_if *tif, struct tcq_class *cl, mbuf_svc_class_t sc,
                len = pktsched_get_pkt_len(pkt);
                IFCQ_DEC_LEN(ifq);
                IFCQ_DEC_BYTES(ifq, len);
-               if (qempty(&cl->cl_q))
+               if (qempty(&cl->cl_q)) {
                        cl->cl_period++;
+               }
                PKTCNTR_ADD(&cl->cl_xmitcnt, 1, len);
                IFCQ_XMIT_ADD(ifq, 1, len);
        }
@@ -526,32 +552,35 @@ tcq_addq(struct tcq_class *cl, pktsched_pkt_t *pkt, struct pf_mtag *t)
                                cqrq_throttle_t tr = { 1, tif->tif_throttle };
                                int err = tcq_throttle(tif, &tr);
 
-                               if (err == EALREADY)
+                               if (err == EALREADY) {
                                        err = 0;
+                               }
                                if (err != 0) {
                                        tr.level = IFNET_THROTTLE_OFF;
                                        (void) tcq_throttle(tif, &tr);
                                }
                        }
                }
-               if (cl->cl_sfb != NULL)
-                       return (sfb_addq(cl->cl_sfb, &cl->cl_q, pkt, t));
+               if (cl->cl_sfb != NULL) {
+                       return sfb_addq(cl->cl_sfb, &cl->cl_q, pkt, t);
+               }
        } else if (qlen(&cl->cl_q) >= qlimit(&cl->cl_q)) {
                IFCQ_CONVERT_LOCK(ifq);
-               return (CLASSQEQ_DROP);
+               return CLASSQEQ_DROP;
        }
 
 #if PF_ECN
-       if (cl->cl_flags & TQCF_CLEARDSCP)
+       if (cl->cl_flags & TQCF_CLEARDSCP) {
                /* not supported for non-BSD stack packets */
                VERIFY(pkt->pktsched_ptype == QP_MBUF);
-               write_dsfield(m, t, 0);
+       }
+       write_dsfield(m, t, 0);
 #endif /* PF_ECN */
 
        VERIFY(pkt->pktsched_ptype == qptype(&cl->cl_q));
        _addq(&cl->cl_q, pkt->pktsched_pkt);
 
-       return (0);
+       return 0;
 }
 
 static inline void
@@ -560,10 +589,10 @@ tcq_getq(struct tcq_class *cl, pktsched_pkt_t *pkt)
        IFCQ_LOCK_ASSERT_HELD(cl->cl_tif->tif_ifq);
 
        if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL) {
-               return (sfb_getq(cl->cl_sfb, &cl->cl_q, pkt));
+               return sfb_getq(cl->cl_sfb, &cl->cl_q, pkt);
        }
 
-       return (pktsched_pkt_encap(pkt, qptype(&cl->cl_q), _getq(&cl->cl_q)));
+       return pktsched_pkt_encap(pkt, qptype(&cl->cl_q), _getq(&cl->cl_q));
 }
 
 static void
@@ -575,14 +604,16 @@ tcq_purgeq(struct tcq_if *tif, struct tcq_class *cl, u_int32_t flow,
 
        IFCQ_LOCK_ASSERT_HELD(ifq);
 
-       if ((qlen = qlen(&cl->cl_q)) == 0)
+       if ((qlen = qlen(&cl->cl_q)) == 0) {
                goto done;
+       }
 
        IFCQ_CONVERT_LOCK(ifq);
-       if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL)
+       if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL) {
                sfb_purgeq(cl->cl_sfb, &cl->cl_q, flow, &cnt, &len);
-       else
+       } else {
                _flushq_flow(&cl->cl_q, flow, &cnt, &len);
+       }
 
        if (cnt > 0) {
                VERIFY(qlen(&cl->cl_q) == (qlen - cnt));
@@ -602,10 +633,12 @@ tcq_purgeq(struct tcq_if *tif, struct tcq_class *cl, u_int32_t flow,
                }
        }
 done:
-       if (packets != NULL)
+       if (packets != NULL) {
                *packets = cnt;
-       if (bytes != NULL)
+       }
+       if (bytes != NULL) {
                *bytes = len;
+       }
 }
 
 static void
@@ -619,8 +652,9 @@ tcq_updateq(struct tcq_if *tif, struct tcq_class *cl, cqev_t ev)
                    cl->cl_handle, cl->cl_pri, ifclassq_ev2str(ev));
        }
 
-       if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL)
-               return (sfb_updateq(cl->cl_sfb, ev));
+       if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL) {
+               return sfb_updateq(cl->cl_sfb, ev);
+       }
 }
 
 int
@@ -631,8 +665,9 @@ tcq_get_class_stats(struct tcq_if *tif, u_int32_t qid,
 
        IFCQ_LOCK_ASSERT_HELD(tif->tif_ifq);
 
-       if ((cl = tcq_clh_to_clp(tif, qid)) == NULL)
-               return (EINVAL);
+       if ((cl = tcq_clh_to_clp(tif, qid)) == NULL) {
+               return EINVAL;
+       }
 
        sp->class_handle = cl->cl_handle;
        sp->priority = cl->cl_pri;
@@ -645,10 +680,11 @@ tcq_get_class_stats(struct tcq_if *tif, u_int32_t qid,
        sp->qtype = qtype(&cl->cl_q);
        sp->qstate = qstate(&cl->cl_q);
 
-       if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL)
+       if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL) {
                sfb_getstats(cl->cl_sfb, &sp->sfb);
+       }
 
-       return (0);
+       return 0;
 }
 
 static int
@@ -669,7 +705,7 @@ tcq_stat_sc(struct tcq_if *tif, cqrq_stat_sc_t *sr)
        sr->packets = qlen(&cl->cl_q);
        sr->bytes = qsize(&cl->cl_q);
 
-       return (0);
+       return 0;
 }
 
 /* convert a class handle to the corresponding class pointer */
@@ -681,19 +717,21 @@ tcq_clh_to_clp(struct tcq_if *tif, u_int32_t chandle)
 
        IFCQ_LOCK_ASSERT_HELD(tif->tif_ifq);
 
-       for (idx = tif->tif_maxpri; idx >= 0; idx--)
+       for (idx = tif->tif_maxpri; idx >= 0; idx--) {
                if ((cl = tif->tif_classes[idx]) != NULL &&
-                   cl->cl_handle == chandle)
-                       return (cl);
+                   cl->cl_handle == chandle) {
+                       return cl;
+               }
+       }
 
-       return (NULL);
+       return NULL;
 }
 
 static const char *
 tcq_style(struct tcq_if *tif)
 {
 #pragma unused(tif)
-       return ("TCQ");
+       return "TCQ";
 }
 
 /*
@@ -720,7 +758,7 @@ tcq_enqueue_ifclassq(struct ifclassq *ifq, void *p, classq_pkt_type_t ptype,
                        IFCQ_CONVERT_LOCK(ifq);
                        m_freem(m);
                        *pdrop = TRUE;
-                       return (ENOBUFS);
+                       return ENOBUFS;
                }
                t =  m_pftag(m);
                i = MBUF_SCIDX(mbuf_get_service_class(m));
@@ -758,7 +796,7 @@ tcq_enqueue_ifclassq(struct ifclassq *ifq, void *p, classq_pkt_type_t ptype,
        default:
                VERIFY(0);
        }
-       return (ret);
+       return ret;
 }
 
 /*
@@ -779,16 +817,16 @@ tcq_dequeue_tc_ifclassq(struct ifclassq *ifq, mbuf_svc_class_t sc,
 
        VERIFY((u_int32_t)i < IFCQ_SC_MAX);
 
-       bzero(&pkt, sizeof (pkt));
+       bzero(&pkt, sizeof(pkt));
        (tcq_dequeue_cl(ifq->ifcq_disc, ifq->ifcq_disc_slots[i].cl, sc, &pkt));
        *ptype = pkt.pktsched_ptype;
-       return (pkt.pktsched_pkt);
+       return pkt.pktsched_pkt;
 }
 
 static int
 tcq_request_ifclassq(struct ifclassq *ifq, cqrq_t req, void *arg)
 {
-       struct tcq_if   *tif = (struct tcq_if *)ifq->ifcq_disc;
+       struct tcq_if   *tif = (struct tcq_if *)ifq->ifcq_disc;
        int err = 0;
 
        IFCQ_LOCK_ASSERT_HELD(ifq);
@@ -814,7 +852,7 @@ tcq_request_ifclassq(struct ifclassq *ifq, cqrq_t req, void *arg)
                err = tcq_stat_sc(tif, (cqrq_stat_sc_t *)arg);
                break;
        }
-       return (err);
+       return err;
 }
 
 int
@@ -831,37 +869,47 @@ tcq_setup_ifclassq(struct ifclassq *ifq, u_int32_t flags,
        VERIFY(ifq->ifcq_disc == NULL);
        VERIFY(ifq->ifcq_type == PKTSCHEDT_NONE);
 
-       if (flags & PKTSCHEDF_QALG_SFB)
+       if (flags & PKTSCHEDF_QALG_SFB) {
                qflags |= TQCF_SFB;
-       if (flags & PKTSCHEDF_QALG_ECN)
+       }
+       if (flags & PKTSCHEDF_QALG_ECN) {
                qflags |= TQCF_ECN;
-       if (flags & PKTSCHEDF_QALG_FLOWCTL)
+       }
+       if (flags & PKTSCHEDF_QALG_FLOWCTL) {
                qflags |= TQCF_FLOWCTL;
-       if (flags & PKTSCHEDF_QALG_DELAYBASED)
+       }
+       if (flags & PKTSCHEDF_QALG_DELAYBASED) {
                qflags |= TQCF_DELAYBASED;
+       }
 
        tif = tcq_alloc(ifp, M_WAITOK);
-       if (tif == NULL)
-               return (ENOMEM);
+       if (tif == NULL) {
+               return ENOMEM;
+       }
 
-       if ((maxlen = IFCQ_MAXLEN(ifq)) == 0)
+       if ((maxlen = IFCQ_MAXLEN(ifq)) == 0) {
                maxlen = if_sndq_maxlen;
+       }
 
        if ((err = tcq_add_queue(tif, 0, maxlen,
-           qflags | TQCF_LAZY, SCIDX_BK, &cl0, ptype)) != 0)
+           qflags | TQCF_LAZY, SCIDX_BK, &cl0, ptype)) != 0) {
                goto cleanup;
+       }
 
        if ((err = tcq_add_queue(tif, 1, maxlen,
-           qflags | TQCF_DEFAULTCLASS, SCIDX_BE, &cl1, ptype)) != 0)
+           qflags | TQCF_DEFAULTCLASS, SCIDX_BE, &cl1, ptype)) != 0) {
                goto cleanup;
+       }
 
        if ((err = tcq_add_queue(tif, 2, maxlen,
-           qflags | TQCF_LAZY, SCIDX_VI, &cl2, ptype)) != 0)
+           qflags | TQCF_LAZY, SCIDX_VI, &cl2, ptype)) != 0) {
                goto cleanup;
+       }
 
        if ((err = tcq_add_queue(tif, 3, maxlen,
-           qflags, SCIDX_VO, &cl3, ptype)) != 0)
+           qflags, SCIDX_VO, &cl3, ptype)) != 0) {
                goto cleanup;
+       }
 
        err = ifclassq_attach(ifq, PKTSCHEDT_TCQ, tif,
            tcq_enqueue_ifclassq, NULL, tcq_dequeue_tc_ifclassq,
@@ -905,10 +953,11 @@ tcq_setup_ifclassq(struct ifclassq *ifq, u_int32_t flags,
        }
 
 cleanup:
-       if (err != 0)
+       if (err != 0) {
                (void) tcq_destroy_locked(tif);
+       }
 
-       return (err);
+       return err;
 }
 
 int
@@ -928,7 +977,7 @@ tcq_teardown_ifclassq(struct ifclassq *ifq)
                ifq->ifcq_disc_slots[i].cl = NULL;
        }
 
-       return (ifclassq_detach(ifq));
+       return ifclassq_detach(ifq);
 }
 
 int
@@ -940,11 +989,12 @@ tcq_getqstats_ifclassq(struct ifclassq *ifq, u_int32_t slot,
        IFCQ_LOCK_ASSERT_HELD(ifq);
        VERIFY(ifq->ifcq_type == PKTSCHEDT_TCQ);
 
-       if (slot >= IFCQ_SC_MAX)
-               return (EINVAL);
+       if (slot >= IFCQ_SC_MAX) {
+               return EINVAL;
+       }
 
-       return (tcq_get_class_stats(tif, ifq->ifcq_disc_slots[slot].qid,
-           &ifqs->ifqs_tcq_stats));
+       return tcq_get_class_stats(tif, ifq->ifcq_disc_slots[slot].qid,
+                  &ifqs->ifqs_tcq_stats);
 }
 
 static int
@@ -958,11 +1008,12 @@ tcq_throttle(struct tcq_if *tif, cqrq_throttle_t *tr)
 
        if (!tr->set) {
                tr->level = tif->tif_throttle;
-               return (0);
+               return 0;
        }
 
-       if (tr->level == tif->tif_throttle)
-               return (EALREADY);
+       if (tr->level == tif->tif_throttle) {
+               return EALREADY;
+       }
 
        /* Current throttling levels only involve BK_SYS class */
        cl = ifq->ifcq_disc_slots[SCIDX_BK_SYS].cl;
@@ -989,17 +1040,18 @@ tcq_throttle(struct tcq_if *tif, cqrq_throttle_t *tr)
                            tr->level);
                }
                tif->tif_throttle = tr->level;
-               if (err != 0)
+               if (err != 0) {
                        err = 0;
-               else
+               } else {
                        tcq_purgeq(tif, cl, 0, NULL, NULL);
+               }
        } else {
                log(LOG_ERR, "%s: %s unable to set throttling level "
                    "%d->%d [error=%d]\n", if_name(TCQIF_IFP(tif)),
                    tcq_style(tif), tif->tif_throttle, tr->level, err);
        }
 
-       return (err);
+       return err;
 }
 
 static int
@@ -1012,13 +1064,15 @@ tcq_resumeq(struct tcq_if *tif, struct tcq_class *cl)
 #endif
        IFCQ_LOCK_ASSERT_HELD(ifq);
 
-       if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL)
+       if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL) {
                err = sfb_suspendq(cl->cl_sfb, &cl->cl_q, FALSE);
+       }
 
-       if (err == 0)
+       if (err == 0) {
                qstate(&cl->cl_q) = QS_RUNNING;
+       }
 
-       return (err);
+       return err;
 }
 
 static int
@@ -1036,12 +1090,13 @@ tcq_suspendq(struct tcq_if *tif, struct tcq_class *cl)
                        err = sfb_suspendq(cl->cl_sfb, &cl->cl_q, TRUE);
                } else {
                        VERIFY(cl->cl_flags & TQCF_LAZY);
-                       err = ENXIO;    /* delayed throttling */
+                       err = ENXIO;    /* delayed throttling */
                }
        }
 
-       if (err == 0 || err == ENXIO)
+       if (err == 0 || err == ENXIO) {
                qstate(&cl->cl_q) = QS_SUSPENDED;
+       }
 
-       return (err);
+       return err;
 }