bool existing = false;
        struct nlattr *tb[TCA_QFQ_MAX + 1];
        struct qfq_aggregate *new_agg = NULL;
-       u32 weight, lmax, inv_w;
+       u32 weight, lmax, inv_w, old_weight, old_lmax;
        int err;
        int delta_w;
 
        inv_w = ONE_FP / weight;
        weight = ONE_FP / inv_w;
 
-       if (cl != NULL &&
-           lmax == cl->agg->lmax &&
-           weight == cl->agg->class_weight)
-               return 0; /* nothing to change */
+       if (cl != NULL) {
+               sch_tree_lock(sch);
+               old_weight = cl->agg->class_weight;
+               old_lmax   = cl->agg->lmax;
+               sch_tree_unlock(sch);
+               if (lmax == old_lmax && weight == old_weight)
+                       return 0; /* nothing to change */
+       }
 
-       delta_w = weight - (cl ? cl->agg->class_weight : 0);
+       delta_w = weight - (cl ? old_weight : 0);
 
        if (q->wsum + delta_w > QFQ_MAX_WSUM) {
                NL_SET_ERR_MSG_FMT_MOD(extack,
 
        qdisc_purge_queue(cl->qdisc);
        qdisc_class_hash_remove(&q->clhash, &cl->common);
+       qfq_destroy_class(sch, cl);
 
        sch_tree_unlock(sch);
 
-       qfq_destroy_class(sch, cl);
        return 0;
 }
 
 {
        struct qfq_class *cl = (struct qfq_class *)arg;
        struct nlattr *nest;
+       u32 class_weight, lmax;
 
        tcm->tcm_parent = TC_H_ROOT;
        tcm->tcm_handle = cl->common.classid;
        nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
        if (nest == NULL)
                goto nla_put_failure;
-       if (nla_put_u32(skb, TCA_QFQ_WEIGHT, cl->agg->class_weight) ||
-           nla_put_u32(skb, TCA_QFQ_LMAX, cl->agg->lmax))
+
+       sch_tree_lock(sch);
+       class_weight    = cl->agg->class_weight;
+       lmax            = cl->agg->lmax;
+       sch_tree_unlock(sch);
+       if (nla_put_u32(skb, TCA_QFQ_WEIGHT, class_weight) ||
+           nla_put_u32(skb, TCA_QFQ_LMAX, lmax))
                goto nla_put_failure;
        return nla_nest_end(skb, nest);
 
 
        memset(&xstats, 0, sizeof(xstats));
 
+       sch_tree_lock(sch);
        xstats.weight = cl->agg->class_weight;
        xstats.lmax = cl->agg->lmax;
+       sch_tree_unlock(sch);
 
        if (gnet_stats_copy_basic(d, NULL, &cl->bstats, true) < 0 ||
            gnet_stats_copy_rate_est(d, &cl->rate_est) < 0 ||