Commit 37a319b5 authored by David S. Miller's avatar David S. Miller

Merge branch 'devlink-fixes-for-port-and-reporter-field-access'

Parav Pandit says:

====================
devlink fixes for port and reporter field access

These series contains two small fixes of devlink.

Patch-1 initializes port reporter fields early enough to
avoid access before initialized error.
Patch-2 protects port list lock during traversal.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 507ebe64 5d080b50
...@@ -5895,6 +5895,7 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg, ...@@ -5895,6 +5895,7 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg,
list_for_each_entry(devlink, &devlink_list, list) { list_for_each_entry(devlink, &devlink_list, list) {
if (!net_eq(devlink_net(devlink), sock_net(msg->sk))) if (!net_eq(devlink_net(devlink), sock_net(msg->sk)))
continue; continue;
mutex_lock(&devlink->lock);
list_for_each_entry(port, &devlink->port_list, list) { list_for_each_entry(port, &devlink->port_list, list) {
mutex_lock(&port->reporters_lock); mutex_lock(&port->reporters_lock);
list_for_each_entry(reporter, &port->reporter_list, list) { list_for_each_entry(reporter, &port->reporter_list, list) {
...@@ -5909,12 +5910,14 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg, ...@@ -5909,12 +5910,14 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg,
NLM_F_MULTI); NLM_F_MULTI);
if (err) { if (err) {
mutex_unlock(&port->reporters_lock); mutex_unlock(&port->reporters_lock);
mutex_unlock(&devlink->lock);
goto out; goto out;
} }
idx++; idx++;
} }
mutex_unlock(&port->reporters_lock); mutex_unlock(&port->reporters_lock);
} }
mutex_unlock(&devlink->lock);
} }
out: out:
mutex_unlock(&devlink_mutex); mutex_unlock(&devlink_mutex);
...@@ -7555,11 +7558,11 @@ int devlink_port_register(struct devlink *devlink, ...@@ -7555,11 +7558,11 @@ int devlink_port_register(struct devlink *devlink,
devlink_port->index = port_index; devlink_port->index = port_index;
devlink_port->registered = true; devlink_port->registered = true;
spin_lock_init(&devlink_port->type_lock); spin_lock_init(&devlink_port->type_lock);
INIT_LIST_HEAD(&devlink_port->reporter_list);
mutex_init(&devlink_port->reporters_lock);
list_add_tail(&devlink_port->list, &devlink->port_list); list_add_tail(&devlink_port->list, &devlink->port_list);
INIT_LIST_HEAD(&devlink_port->param_list); INIT_LIST_HEAD(&devlink_port->param_list);
mutex_unlock(&devlink->lock); mutex_unlock(&devlink->lock);
INIT_LIST_HEAD(&devlink_port->reporter_list);
mutex_init(&devlink_port->reporters_lock);
INIT_DELAYED_WORK(&devlink_port->type_warn_dw, &devlink_port_type_warn); INIT_DELAYED_WORK(&devlink_port->type_warn_dw, &devlink_port_type_warn);
devlink_port_type_warn_schedule(devlink_port); devlink_port_type_warn_schedule(devlink_port);
devlink_port_notify(devlink_port, DEVLINK_CMD_PORT_NEW); devlink_port_notify(devlink_port, DEVLINK_CMD_PORT_NEW);
...@@ -7576,13 +7579,13 @@ void devlink_port_unregister(struct devlink_port *devlink_port) ...@@ -7576,13 +7579,13 @@ void devlink_port_unregister(struct devlink_port *devlink_port)
{ {
struct devlink *devlink = devlink_port->devlink; struct devlink *devlink = devlink_port->devlink;
WARN_ON(!list_empty(&devlink_port->reporter_list));
mutex_destroy(&devlink_port->reporters_lock);
devlink_port_type_warn_cancel(devlink_port); devlink_port_type_warn_cancel(devlink_port);
devlink_port_notify(devlink_port, DEVLINK_CMD_PORT_DEL); devlink_port_notify(devlink_port, DEVLINK_CMD_PORT_DEL);
mutex_lock(&devlink->lock); mutex_lock(&devlink->lock);
list_del(&devlink_port->list); list_del(&devlink_port->list);
mutex_unlock(&devlink->lock); mutex_unlock(&devlink->lock);
WARN_ON(!list_empty(&devlink_port->reporter_list));
mutex_destroy(&devlink_port->reporters_lock);
} }
EXPORT_SYMBOL_GPL(devlink_port_unregister); EXPORT_SYMBOL_GPL(devlink_port_unregister);
......
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