]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
devlink: introduce __devlink_alloc() with dev driver pointer
authorJiri Pirko <jiri@nvidia.com>
Thu, 12 Mar 2026 10:04:01 +0000 (11:04 +0100)
committerJakub Kicinski <kuba@kernel.org>
Sat, 14 Mar 2026 20:08:48 +0000 (13:08 -0700)
Introduce __devlink_alloc() as an internal devlink allocator that
accepts a struct device_driver pointer and stores it in the devlink
instance. This allows internal devlink code (e.g. shared instances)
to associate a driver with a devlink instance without need to pass dev
pointer.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Link: https://patch.msgid.link/20260312100407.551173-8-jiri@resnulli.us
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/devlink/core.c
net/devlink/devl_internal.h

index 237558abcd63443d107cc93733e126d12d3f9a00..fcb73d3e56aad322159ef18a492b552e4c4a4b69 100644 (file)
@@ -418,27 +418,15 @@ void devlink_unregister(struct devlink *devlink)
 }
 EXPORT_SYMBOL_GPL(devlink_unregister);
 
-/**
- *     devlink_alloc_ns - Allocate new devlink instance resources
- *     in specific namespace
- *
- *     @ops: ops
- *     @priv_size: size of user private data
- *     @net: net namespace
- *     @dev: parent device
- *
- *     Allocate new devlink instance resources, including devlink index
- *     and name.
- */
-struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,
-                                size_t priv_size, struct net *net,
-                                struct device *dev)
+struct devlink *__devlink_alloc(const struct devlink_ops *ops, size_t priv_size,
+                               struct net *net, struct device *dev,
+                               const struct device_driver *dev_driver)
 {
        struct devlink *devlink;
        static u32 last_id;
        int ret;
 
-       WARN_ON(!ops || !dev);
+       WARN_ON(!ops || !dev || !dev_driver);
        if (!devlink_reload_actions_valid(ops))
                return NULL;
 
@@ -453,6 +441,7 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,
 
        devlink->dev = get_device(dev);
        devlink->ops = ops;
+       devlink->dev_driver = dev_driver;
        xa_init_flags(&devlink->ports, XA_FLAGS_ALLOC);
        xa_init_flags(&devlink->params, XA_FLAGS_ALLOC);
        xa_init_flags(&devlink->snapshot_ids, XA_FLAGS_ALLOC);
@@ -480,6 +469,25 @@ err_xa_alloc:
        kvfree(devlink);
        return NULL;
 }
+
+/**
+ *     devlink_alloc_ns - Allocate new devlink instance resources
+ *     in specific namespace
+ *
+ *     @ops: ops
+ *     @priv_size: size of user private data
+ *     @net: net namespace
+ *     @dev: parent device
+ *
+ *     Allocate new devlink instance resources, including devlink index
+ *     and name.
+ */
+struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,
+                                size_t priv_size, struct net *net,
+                                struct device *dev)
+{
+       return __devlink_alloc(ops, priv_size, net, dev, dev->driver);
+}
 EXPORT_SYMBOL_GPL(devlink_alloc_ns);
 
 /**
index f0ebfb936770385fdba8c34f4b839f4f53b78580..3cc7e696e0fd971e3663acd9ec126a4362d44960 100644 (file)
@@ -49,6 +49,7 @@ struct devlink {
        struct xarray snapshot_ids;
        struct devlink_dev_stats stats;
        struct device *dev;
+       const struct device_driver *dev_driver;
        possible_net_t _net;
        /* Serializes access to devlink instance specific objects such as
         * port, sb, dpipe, resource, params, region, traps and more.
@@ -66,6 +67,10 @@ struct devlink {
 extern struct xarray devlinks;
 extern struct genl_family devlink_nl_family;
 
+struct devlink *__devlink_alloc(const struct devlink_ops *ops, size_t priv_size,
+                               struct net *net, struct device *dev,
+                               const struct device_driver *dev_driver);
+
 /* devlink instances are open to the access from the user space after
  * devlink_register() call. Such logical barrier allows us to have certain
  * expectations related to locking.