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

net/sched: act_mirred: Add helper function tcf_mirred_replace_dev

The act of replacing a device will be repeated by the init logic for the
block ID in the patch that allows mirred to a block. Therefore we
encapsulate this functionality in a function (tcf_mirred_replace_dev) so
that we can reuse it and avoid code repetition.

Co-developed-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
Co-developed-by: Pedro Tammela <pctammela@mojatatu.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Signed-off-by: Victor Nogueira <victor@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Victor Nogueira and committed by
David S. Miller
415e38bf 16085e48

+12 -4
+12 -4
net/sched/act_mirred.c
··· 89 89 90 90 static struct tc_action_ops act_mirred_ops; 91 91 92 + static void tcf_mirred_replace_dev(struct tcf_mirred *m, 93 + struct net_device *ndev) 94 + { 95 + struct net_device *odev; 96 + 97 + odev = rcu_replace_pointer(m->tcfm_dev, ndev, 98 + lockdep_is_held(&m->tcf_lock)); 99 + netdev_put(odev, &m->tcfm_dev_tracker); 100 + } 101 + 92 102 static int tcf_mirred_init(struct net *net, struct nlattr *nla, 93 103 struct nlattr *est, struct tc_action **a, 94 104 struct tcf_proto *tp, ··· 180 170 spin_lock_bh(&m->tcf_lock); 181 171 182 172 if (parm->ifindex) { 183 - struct net_device *odev, *ndev; 173 + struct net_device *ndev; 184 174 185 175 ndev = dev_get_by_index(net, parm->ifindex); 186 176 if (!ndev) { ··· 189 179 goto put_chain; 190 180 } 191 181 mac_header_xmit = dev_is_mac_header_xmit(ndev); 192 - odev = rcu_replace_pointer(m->tcfm_dev, ndev, 193 - lockdep_is_held(&m->tcf_lock)); 194 - netdev_put(odev, &m->tcfm_dev_tracker); 182 + tcf_mirred_replace_dev(m, ndev); 195 183 netdev_tracker_alloc(ndev, &m->tcfm_dev_tracker, GFP_ATOMIC); 196 184 m->tcfm_mac_header_xmit = mac_header_xmit; 197 185 }