Commit bb047ddd authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

net: sched: don't set q pointer for shared blocks

It is pointless to set block->q for block which are shared among
multiple qdiscs. So remove the assignment in that case. Do a bit of code
reshuffle to make block->index initialized at that point so we can use
tcf_block_shared() helper.
Reported-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
Fixes: 48617387 ("net: sched: introduce shared filter blocks infrastructure")
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0f2d2b27
...@@ -376,17 +376,12 @@ struct tcf_net { ...@@ -376,17 +376,12 @@ struct tcf_net {
static unsigned int tcf_net_id; static unsigned int tcf_net_id;
static int tcf_block_insert(struct tcf_block *block, struct net *net, static int tcf_block_insert(struct tcf_block *block, struct net *net,
u32 block_index, struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct tcf_net *tn = net_generic(net, tcf_net_id); struct tcf_net *tn = net_generic(net, tcf_net_id);
int err;
err = idr_alloc_u32(&tn->idr, block, &block_index, block_index, return idr_alloc_u32(&tn->idr, block, &block->index, block->index,
GFP_KERNEL); GFP_KERNEL);
if (err)
return err;
block->index = block_index;
return 0;
} }
static void tcf_block_remove(struct tcf_block *block, struct net *net) static void tcf_block_remove(struct tcf_block *block, struct net *net)
...@@ -397,6 +392,7 @@ static void tcf_block_remove(struct tcf_block *block, struct net *net) ...@@ -397,6 +392,7 @@ static void tcf_block_remove(struct tcf_block *block, struct net *net)
} }
static struct tcf_block *tcf_block_create(struct net *net, struct Qdisc *q, static struct tcf_block *tcf_block_create(struct net *net, struct Qdisc *q,
u32 block_index,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct tcf_block *block; struct tcf_block *block;
...@@ -419,10 +415,13 @@ static struct tcf_block *tcf_block_create(struct net *net, struct Qdisc *q, ...@@ -419,10 +415,13 @@ static struct tcf_block *tcf_block_create(struct net *net, struct Qdisc *q,
err = -ENOMEM; err = -ENOMEM;
goto err_chain_create; goto err_chain_create;
} }
block->net = qdisc_net(q);
block->refcnt = 1; block->refcnt = 1;
block->net = net; block->net = net;
block->q = q; block->index = block_index;
/* Don't store q pointer for blocks which are shared */
if (!tcf_block_shared(block))
block->q = q;
return block; return block;
err_chain_create: err_chain_create:
...@@ -518,13 +517,12 @@ int tcf_block_get_ext(struct tcf_block **p_block, struct Qdisc *q, ...@@ -518,13 +517,12 @@ int tcf_block_get_ext(struct tcf_block **p_block, struct Qdisc *q,
} }
if (!block) { if (!block) {
block = tcf_block_create(net, q, extack); block = tcf_block_create(net, q, ei->block_index, extack);
if (IS_ERR(block)) if (IS_ERR(block))
return PTR_ERR(block); return PTR_ERR(block);
created = true; created = true;
if (ei->block_index) { if (tcf_block_shared(block)) {
err = tcf_block_insert(block, net, err = tcf_block_insert(block, net, extack);
ei->block_index, extack);
if (err) if (err)
goto err_block_insert; goto err_block_insert;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment