[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1551418672-12822-6-git-send-email-parav@mellanox.com>
Date: Thu, 28 Feb 2019 23:37:49 -0600
From: Parav Pandit <parav@...lanox.com>
To: netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
michal.lkml@...kovi.net, davem@...emloft.net,
gregkh@...uxfoundation.org, jiri@...lanox.com
Cc: parav@...lanox.com
Subject: [RFC net-next 5/8] devlink: Add variant of devlink_register/unregister
Add variants of devlink_register and devlink_unregister which doesn't
explicitly acquire/release devlink_mutex lock, but requires that caller
hold the devlink_mutex lock.
This is required to create child devlink devices while working on
parent devlink device.
Change-Id: I74417158144b28ff51ecfb2d1105c83ebefdf985
Signed-off-by: Parav Pandit <parav@...lanox.com>
---
include/net/devlink.h | 15 ++++++++++++++-
net/core/devlink.c | 36 +++++++++++++++++++++++++++++++-----
2 files changed, 45 insertions(+), 6 deletions(-)
diff --git a/include/net/devlink.h b/include/net/devlink.h
index ae5e0e6..9a067b1 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -545,7 +545,9 @@ static inline struct devlink *priv_to_devlink(void *priv)
void devlink_init(struct devlink *devlink, const struct devlink_ops *ops);
void devlink_cleanup(struct devlink *devlink);
struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
+void __devlink_register(struct devlink *devlink, struct device *dev);
int devlink_register(struct devlink *devlink, struct device *dev);
+void __devlink_unregister(struct devlink *devlink);
void devlink_unregister(struct devlink *devlink);
void devlink_free(struct devlink *devlink);
int devlink_port_register(struct devlink *devlink,
@@ -713,6 +715,7 @@ int devlink_health_report(struct devlink_health_reporter *reporter,
static inline void devlink_init(struct devlink *devlink,
const struct devlink_ops *ops)
+{
}
static inline void devlink_cleanup(struct devlink *devlink)
@@ -725,11 +728,21 @@ static inline struct devlink *devlink_alloc(const struct devlink_ops *ops,
return kzalloc(sizeof(struct devlink) + priv_size, GFP_KERNEL);
}
-static inline int devlink_register(struct devlink *devlink, struct device *dev)
+static inline void __devlink_register(struct devlink *devlink,
+ struct device *dev)
+{
+}
+
+static inline int devlink_register(struct devlink *devlink,
+ struct device *dev)
{
return 0;
}
+static inline void __devlink_unregister(struct devlink *devlink)
+{
+}
+
static inline void devlink_unregister(struct devlink *devlink)
{
}
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 25492c6..cfbad2c 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -5262,22 +5262,49 @@ struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size)
EXPORT_SYMBOL_GPL(devlink_alloc);
/**
- * devlink_register - Register devlink instance
+ * __devlink_register - Register devlink instance
+ * Caller must hold devlink_mutex.
*
* @devlink: devlink
*/
-int devlink_register(struct devlink *devlink, struct device *dev)
+void __devlink_register(struct devlink *devlink, struct device *dev)
{
- mutex_lock(&devlink_mutex);
+ lockdep_assert_held(&devlink_mutex);
devlink->dev = dev;
list_add_tail(&devlink->list, &devlink_list);
devlink_notify(devlink, DEVLINK_CMD_NEW);
+}
+EXPORT_SYMBOL_GPL(__devlink_register);
+
+/**
+ * devlink_register - Register devlink instance
+ *
+ * @devlink: devlink
+ */
+int devlink_register(struct devlink *devlink, struct device *dev)
+{
+ mutex_lock(&devlink_mutex);
+ __devlink_register(devlink, dev);
mutex_unlock(&devlink_mutex);
return 0;
}
EXPORT_SYMBOL_GPL(devlink_register);
/**
+ * __devlink_unregister - Unregister devlink instance
+ * Caller must hold the devlink_mutex while invoking this API.
+ *
+ * @devlink: devlink
+ */
+void __devlink_unregister(struct devlink *devlink)
+{
+ lockdep_assert_held(&devlink_mutex);
+ devlink_notify(devlink, DEVLINK_CMD_DEL);
+ list_del(&devlink->list);
+}
+EXPORT_SYMBOL_GPL(__devlink_unregister);
+
+/**
* devlink_unregister - Unregister devlink instance
*
* @devlink: devlink
@@ -5285,8 +5312,7 @@ int devlink_register(struct devlink *devlink, struct device *dev)
void devlink_unregister(struct devlink *devlink)
{
mutex_lock(&devlink_mutex);
- devlink_notify(devlink, DEVLINK_CMD_DEL);
- list_del(&devlink->list);
+ __devlink_unregister(devlink);
mutex_unlock(&devlink_mutex);
}
EXPORT_SYMBOL_GPL(devlink_unregister);
--
1.8.3.1
Powered by blists - more mailing lists