summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2020-07-21 16:14:58 -0700
committerDavid S. Miller <davem@davemloft.net>2020-07-21 16:14:58 -0700
commit1fe4085f90bca7001f3713c651b4c7368cac779a (patch)
tree1420ff4aef977d292eafab0e9b856b6dde6bd159
parent3fc364c0527494f322ad9504a39d39a6197edfdc (diff)
parenteac5f8a95ae39dd94af818f0f9fad5d46207ee33 (diff)
Merge branch 'devlink-small-improvements'
Parav Pandit says: ==================== devlink small improvements This short series improves the devlink code for lock commment, simplifying checks and keeping the scope of mutex lock for necessary fields. Patch summary: Patch-1 Keep the devlink_mutex for only for necessary changes. Patch-2 Avoids duplicate check for reload flag Patch-3 Adds missing comment for the scope of devlink instance lock Patch-4 Constify devlink instance pointer ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/devlink.h4
-rw-r--r--net/core/devlink.c6
2 files changed, 6 insertions, 4 deletions
diff --git a/include/net/devlink.h b/include/net/devlink.h
index 913e8679ae35..19d990c8edcc 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -40,7 +40,9 @@ struct devlink {
struct xarray snapshot_ids;
struct device *dev;
possible_net_t _net;
- struct mutex lock;
+ struct mutex lock; /* Serializes access to devlink instance specific objects such as
+ * port, sb, dpipe, resource, params, region, traps and more.
+ */
u8 reload_failed:1,
reload_enabled:1,
registered:1;
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 6335e1851088..8b7bb4bfb6d0 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -2921,7 +2921,7 @@ static void devlink_reload_netns_change(struct devlink *devlink,
DEVLINK_CMD_PARAM_NEW);
}
-static bool devlink_reload_supported(struct devlink *devlink)
+static bool devlink_reload_supported(const struct devlink *devlink)
{
return devlink->ops->reload_down && devlink->ops->reload_up;
}
@@ -2967,7 +2967,7 @@ static int devlink_nl_cmd_reload(struct sk_buff *skb, struct genl_info *info)
struct net *dest_net = NULL;
int err;
- if (!devlink_reload_supported(devlink) || !devlink->reload_enabled)
+ if (!devlink_reload_supported(devlink))
return -EOPNOTSUPP;
err = devlink_resources_validate(devlink, NULL, info);
@@ -7421,9 +7421,9 @@ EXPORT_SYMBOL_GPL(devlink_alloc);
*/
int devlink_register(struct devlink *devlink, struct device *dev)
{
- mutex_lock(&devlink_mutex);
devlink->dev = dev;
devlink->registered = true;
+ mutex_lock(&devlink_mutex);
list_add_tail(&devlink->list, &devlink_list);
devlink_notify(devlink, DEVLINK_CMD_NEW);
mutex_unlock(&devlink_mutex);