Commit 35713d9b authored by David S. Miller's avatar David S. Miller

Merge branch 'devlink-rate-limit-fixes'

Dmytro Linkin says:

====================
Fixes for devlink rate objects API

Patch #1 fixes not decreased refcount of parent node for destroyed leaf
object.

Patch #2 fixes incorect eswitch mode check.

Patch #3 protects list traversing with a lock.

====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents a2f7dc00 a3e5e579
...@@ -2709,23 +2709,16 @@ static int devlink_rate_nodes_check(struct devlink *devlink, u16 mode, ...@@ -2709,23 +2709,16 @@ static int devlink_rate_nodes_check(struct devlink *devlink, u16 mode,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct devlink_rate *devlink_rate; struct devlink_rate *devlink_rate;
u16 old_mode;
int err;
if (!devlink->ops->eswitch_mode_get)
return -EOPNOTSUPP;
err = devlink->ops->eswitch_mode_get(devlink, &old_mode);
if (err)
return err;
if (old_mode == mode)
return 0;
/* Take the lock to sync with devlink_rate_nodes_destroy() */
mutex_lock(&devlink->lock);
list_for_each_entry(devlink_rate, &devlink->rate_list, list) list_for_each_entry(devlink_rate, &devlink->rate_list, list)
if (devlink_rate_is_node(devlink_rate)) { if (devlink_rate_is_node(devlink_rate)) {
mutex_unlock(&devlink->lock);
NL_SET_ERR_MSG_MOD(extack, "Rate node(s) exists."); NL_SET_ERR_MSG_MOD(extack, "Rate node(s) exists.");
return -EBUSY; return -EBUSY;
} }
mutex_unlock(&devlink->lock);
return 0; return 0;
} }
...@@ -9275,6 +9268,8 @@ void devlink_rate_leaf_destroy(struct devlink_port *devlink_port) ...@@ -9275,6 +9268,8 @@ void devlink_rate_leaf_destroy(struct devlink_port *devlink_port)
mutex_lock(&devlink->lock); mutex_lock(&devlink->lock);
devlink_rate_notify(devlink_rate, DEVLINK_CMD_RATE_DEL); devlink_rate_notify(devlink_rate, DEVLINK_CMD_RATE_DEL);
if (devlink_rate->parent)
refcount_dec(&devlink_rate->parent->refcnt);
list_del(&devlink_rate->list); list_del(&devlink_rate->list);
devlink_port->devlink_rate = NULL; devlink_port->devlink_rate = NULL;
mutex_unlock(&devlink->lock); mutex_unlock(&devlink->lock);
......
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