From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, saeedm@nvidia.com, leon@kernel.org,
tariqt@nvidia.com, andrew+netdev@lunn.ch, dakr@kernel.org,
rafael@kernel.org, gregkh@linuxfoundation.org,
przemyslaw.kitszel@intel.com, anthony.l.nguyen@intel.com,
cratiu@nvidia.com, jacob.e.keller@intel.com,
konrad.knitter@intel.com, cjubran@nvidia.com
Subject: [PATCH net-next RFC 1/3] faux: extend the creation function for module namespace
Date: Tue, 18 Mar 2025 13:47:04 +0100 [thread overview]
Message-ID: <20250318124706.94156-2-jiri@resnulli.us> (raw)
In-Reply-To: <20250318124706.94156-1-jiri@resnulli.us>
From: Jiri Pirko <jiri@nvidia.com>
It is hard for the faux user to avoid potential name conflicts, as it is
only in control of faux devices it creates. Therefore extend the faux
device creation function by module parameter, embed the module name into
the device name in format "modulename_permodulename" and allow module to
control it's namespace.
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
drivers/base/faux.c | 20 ++++++++++++--------
include/linux/device/faux.h | 6 ++++--
include/linux/module.h | 2 +-
3 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/drivers/base/faux.c b/drivers/base/faux.c
index 531e9d789ee0..b1fcac6b0946 100644
--- a/drivers/base/faux.c
+++ b/drivers/base/faux.c
@@ -85,8 +85,9 @@ static void faux_device_release(struct device *dev)
* faux_device_create_with_groups - Create and register with the driver
* core a faux device and populate the device with an initial
* set of sysfs attributes.
- * @name: The name of the device we are adding, must be unique for
- * all faux devices.
+ * @module: Pointer to module this device is associated.
+ * @name: The name of the device we are adding, must be unique for all
+ * faux devices within a single module.
* @parent: Pointer to a potential parent struct device. If set to
* NULL, the device will be created in the "root" of the faux
* device tree in sysfs.
@@ -108,7 +109,8 @@ static void faux_device_release(struct device *dev)
* * NULL if an error happened with creating the device
* * pointer to a valid struct faux_device that is registered with sysfs
*/
-struct faux_device *faux_device_create_with_groups(const char *name,
+struct faux_device *faux_device_create_with_groups(const struct module *module,
+ const char *name,
struct device *parent,
const struct faux_device_ops *faux_ops,
const struct attribute_group **groups)
@@ -137,12 +139,12 @@ struct faux_device *faux_device_create_with_groups(const char *name,
dev->parent = &faux_bus_root;
dev->bus = &faux_bus_type;
dev->groups = groups;
- dev_set_name(dev, "%s", name);
+ dev_set_name(dev, "%s_%s", module_name(module), name);
ret = device_add(dev);
if (ret) {
pr_err("%s: device_add for faux device '%s' failed with %d\n",
- __func__, name, ret);
+ __func__, dev_name(dev), ret);
put_device(dev);
return NULL;
}
@@ -153,8 +155,9 @@ EXPORT_SYMBOL_GPL(faux_device_create_with_groups);
/**
* faux_device_create - create and register with the driver core a faux device
+ * @module: Pointer to module this device is associated.
* @name: The name of the device we are adding, must be unique for all
- * faux devices.
+ * faux devices within a single module.
* @parent: Pointer to a potential parent struct device. If set to
* NULL, the device will be created in the "root" of the faux
* device tree in sysfs.
@@ -174,11 +177,12 @@ EXPORT_SYMBOL_GPL(faux_device_create_with_groups);
* * NULL if an error happened with creating the device
* * pointer to a valid struct faux_device that is registered with sysfs
*/
-struct faux_device *faux_device_create(const char *name,
+struct faux_device *faux_device_create(const struct module *module,
+ const char *name,
struct device *parent,
const struct faux_device_ops *faux_ops)
{
- return faux_device_create_with_groups(name, parent, faux_ops, NULL);
+ return faux_device_create_with_groups(module, name, parent, faux_ops, NULL);
}
EXPORT_SYMBOL_GPL(faux_device_create);
diff --git a/include/linux/device/faux.h b/include/linux/device/faux.h
index 9f43c0e46aa4..b1393a34b4f9 100644
--- a/include/linux/device/faux.h
+++ b/include/linux/device/faux.h
@@ -47,10 +47,12 @@ struct faux_device_ops {
void (*remove)(struct faux_device *faux_dev);
};
-struct faux_device *faux_device_create(const char *name,
+struct faux_device *faux_device_create(const struct module *module,
+ const char *name,
struct device *parent,
const struct faux_device_ops *faux_ops);
-struct faux_device *faux_device_create_with_groups(const char *name,
+struct faux_device *faux_device_create_with_groups(const struct module *module,
+ const char *name,
struct device *parent,
const struct faux_device_ops *faux_ops,
const struct attribute_group **groups);
diff --git a/include/linux/module.h b/include/linux/module.h
index 30e5b19bafa9..8d1a7e65d2e4 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -744,7 +744,7 @@ static inline void __module_get(struct module *module)
/* This is a #define so the string doesn't get put in every .o file */
#define module_name(mod) \
({ \
- struct module *__mod = (mod); \
+ const struct module *__mod = (mod); \
__mod ? __mod->name : "kernel"; \
})
--
2.48.1
next prev parent reply other threads:[~2025-03-18 12:47 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-18 12:47 [PATCH net-next RFC 0/3] net/mlx5: Introduce shared devlink instance for PFs on same chip Jiri Pirko
2025-03-18 12:47 ` Jiri Pirko [this message]
2025-03-18 13:46 ` [PATCH net-next RFC 1/3] faux: extend the creation function for module namespace Greg KH
2025-03-18 14:19 ` Jiri Pirko
2025-03-18 14:36 ` Greg KH
2025-03-18 15:26 ` Jiri Pirko
2025-03-18 16:04 ` Greg KH
2025-03-18 16:51 ` Jiri Pirko
2025-03-18 17:27 ` Greg KH
2025-03-19 11:42 ` Jiri Pirko
2025-03-18 12:47 ` [PATCH net-next RFC 2/3] net/mlx5: Introduce shared devlink instance for PFs on same chip Jiri Pirko
2025-03-18 22:05 ` Keller, Jacob E
2025-03-19 8:21 ` Przemek Kitszel
2025-03-19 11:56 ` Jiri Pirko
2025-03-19 13:20 ` Przemek Kitszel
2025-03-19 18:42 ` Keller, Jacob E
2025-03-19 11:44 ` Jiri Pirko
2025-03-18 12:47 ` [PATCH net-next RFC 3/3] net/mlx5: Introduce enable_sriov param for shared devlink Jiri Pirko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250318124706.94156-2-jiri@resnulli.us \
--to=jiri@resnulli.us \
--cc=andrew+netdev@lunn.ch \
--cc=anthony.l.nguyen@intel.com \
--cc=cjubran@nvidia.com \
--cc=cratiu@nvidia.com \
--cc=dakr@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=jacob.e.keller@intel.com \
--cc=konrad.knitter@intel.com \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=przemyslaw.kitszel@intel.com \
--cc=rafael@kernel.org \
--cc=saeedm@nvidia.com \
--cc=tariqt@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).