net/sched: taprio: use rtnl_dereference for oper and admin sched in taprio_destroy()
authorVladimir Oltean <vladimir.oltean@nxp.com>
Thu, 15 Sep 2022 10:50:42 +0000 (13:50 +0300)
committerJakub Kicinski <kuba@kernel.org>
Tue, 20 Sep 2022 20:53:33 +0000 (13:53 -0700)
Sparse complains that taprio_destroy() dereferences q->oper_sched and
q->admin_sched without rcu_dereference(), since they are marked as __rcu
in the taprio private structure.

1671:28: warning: incorrect type in argument 1 (different address spaces)
1671:28:    expected struct callback_head *head
1671:28:    got struct callback_head [noderef] __rcu *
1674:28: warning: incorrect type in argument 1 (different address spaces)
1674:28:    expected struct callback_head *head
1674:28:    got struct callback_head [noderef] __rcu *

To silence that build warning, do actually use rtnl_dereference(), since
we know the rtnl_mutex is held at the time of q->destroy().

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/sched/sch_taprio.c

index 017ccf5431aa8031806592eb238e56b2dcec0790..38d742b335d004da4e2fb556102d2b3f514ecfd5 100644 (file)
@@ -1634,6 +1634,7 @@ static void taprio_destroy(struct Qdisc *sch)
 {
        struct taprio_sched *q = qdisc_priv(sch);
        struct net_device *dev = qdisc_dev(sch);
+       struct sched_gate_list *oper, *admin;
        unsigned int i;
 
        spin_lock(&taprio_list_lock);
@@ -1657,11 +1658,14 @@ static void taprio_destroy(struct Qdisc *sch)
 
        netdev_reset_tc(dev);
 
-       if (q->oper_sched)
-               call_rcu(&q->oper_sched->rcu, taprio_free_sched_cb);
+       oper = rtnl_dereference(q->oper_sched);
+       admin = rtnl_dereference(q->admin_sched);
+
+       if (oper)
+               call_rcu(&oper->rcu, taprio_free_sched_cb);
 
-       if (q->admin_sched)
-               call_rcu(&q->admin_sched->rcu, taprio_free_sched_cb);
+       if (admin)
+               call_rcu(&admin->rcu, taprio_free_sched_cb);
 }
 
 static int taprio_init(struct Qdisc *sch, struct nlattr *opt,