Commit 09fd1e0d authored by Vladimir Oltean's avatar Vladimir Oltean Committed by Jakub Kicinski

net: mscc: ocelot: use list_for_each_entry in ocelot_vcap_filter_add_to_block

Unify the code paths for adding to an empty list and to a list with
elements by keeping a "pos" list_head element that indicates where to
insert. Initialize "pos" with the list head itself in case
list_for_each_entry() doesn't iterate over any element.

Note that list_for_each_safe() isn't needed because no element is
removed from the list while iterating.
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 3825a0d0
...@@ -993,8 +993,8 @@ static int ocelot_vcap_filter_add_to_block(struct ocelot *ocelot, ...@@ -993,8 +993,8 @@ static int ocelot_vcap_filter_add_to_block(struct ocelot *ocelot,
struct ocelot_vcap_filter *filter, struct ocelot_vcap_filter *filter,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct list_head *pos = &block->rules;
struct ocelot_vcap_filter *tmp; struct ocelot_vcap_filter *tmp;
struct list_head *pos, *n;
int ret; int ret;
ret = ocelot_vcap_filter_add_aux_resources(ocelot, filter, extack); ret = ocelot_vcap_filter_add_aux_resources(ocelot, filter, extack);
...@@ -1003,15 +1003,11 @@ static int ocelot_vcap_filter_add_to_block(struct ocelot *ocelot, ...@@ -1003,15 +1003,11 @@ static int ocelot_vcap_filter_add_to_block(struct ocelot *ocelot,
block->count++; block->count++;
if (list_empty(&block->rules)) { list_for_each_entry(tmp, &block->rules, list) {
list_add_tail(&filter->list, &block->rules); if (filter->prio < tmp->prio) {
return 0; pos = &tmp->list;
}
list_for_each_safe(pos, n, &block->rules) {
tmp = list_entry(pos, struct ocelot_vcap_filter, list);
if (filter->prio < tmp->prio)
break; break;
}
} }
list_add_tail(&filter->list, pos); list_add_tail(&filter->list, pos);
......
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