[PATCH 3/3] RDMA/hfi1: reduce namespace pollution
From: Arnd Bergmann
Date: Fri Mar 20 2026 - 11:22:15 EST
From: Arnd Bergmann <arnd@xxxxxxxx>
While looking at an unrelated bug, I noticed that the global "class_name"
function is not suitable for a driver-internal interface. The same
file that declares this also has dev_init() and dev_exit() functions,
which are equally problematic.
Remove the class_name() function entirely and just hardcode the string
where it is used, and rename the other two functions to fit into the
hfi1 namespace.
Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
----
The driver contains many more functions that should not be in the global
namespace, but I decided not to fix the other ones. Maybe the maintainers
can continue renaming the rest.
---
drivers/infiniband/hw/hfi1/debugfs.c | 2 +-
drivers/infiniband/hw/hfi1/device.c | 11 ++---------
drivers/infiniband/hw/hfi1/device.h | 5 ++---
drivers/infiniband/hw/hfi1/file_ops.c | 2 +-
drivers/infiniband/hw/hfi1/init.c | 8 ++++----
5 files changed, 10 insertions(+), 18 deletions(-)
diff --git a/drivers/infiniband/hw/hfi1/debugfs.c b/drivers/infiniband/hw/hfi1/debugfs.c
index ac37ab7f8995..24346b74d5e0 100644
--- a/drivers/infiniband/hw/hfi1/debugfs.c
+++ b/drivers/infiniband/hw/hfi1/debugfs.c
@@ -1161,7 +1161,7 @@ void hfi1_dbg_ibdev_init(struct hfi1_ibdev *ibd)
if (!hfi1_dbg_root)
return;
- snprintf(name, sizeof(name), "%s_%d", class_name(), unit);
+ snprintf(name, sizeof(name), "hfi1_%d", unit);
snprintf(link, sizeof(link), "%d", unit);
root = debugfs_create_dir(name, hfi1_dbg_root);
ibd->hfi1_ibdev_dbg = root;
diff --git a/drivers/infiniband/hw/hfi1/device.c b/drivers/infiniband/hw/hfi1/device.c
index 1aac6c2f45b4..a26b71867a2a 100644
--- a/drivers/infiniband/hw/hfi1/device.c
+++ b/drivers/infiniband/hw/hfi1/device.c
@@ -86,14 +86,7 @@ void hfi1_cdev_cleanup(struct cdev *cdev, struct device **devp)
}
}
-static const char *hfi1_class_name = "hfi1";
-
-const char *class_name(void)
-{
- return hfi1_class_name;
-}
-
-int __init dev_init(void)
+int __init hfi1_dev_init(void)
{
int ret;
@@ -123,7 +116,7 @@ int __init dev_init(void)
return ret;
}
-void dev_cleanup(void)
+void hfi1_dev_cleanup(void)
{
class_unregister(&class);
class_unregister(&user_class);
diff --git a/drivers/infiniband/hw/hfi1/device.h b/drivers/infiniband/hw/hfi1/device.h
index a91bea426ba5..d7775f92e0b1 100644
--- a/drivers/infiniband/hw/hfi1/device.h
+++ b/drivers/infiniband/hw/hfi1/device.h
@@ -12,8 +12,7 @@ int hfi1_cdev_init(int minor, const char *name,
bool user_accessible,
struct kobject *parent);
void hfi1_cdev_cleanup(struct cdev *cdev, struct device **devp);
-const char *class_name(void);
-int __init dev_init(void);
-void dev_cleanup(void);
+int __init hfi1_dev_init(void);
+void hfi1_dev_cleanup(void);
#endif /* _HFI1_DEVICE_H */
diff --git a/drivers/infiniband/hw/hfi1/file_ops.c b/drivers/infiniband/hw/hfi1/file_ops.c
index 56031becb273..2fe7f7df7d09 100644
--- a/drivers/infiniband/hw/hfi1/file_ops.c
+++ b/drivers/infiniband/hw/hfi1/file_ops.c
@@ -1686,7 +1686,7 @@ static int user_add(struct hfi1_devdata *dd)
char name[10];
int ret;
- snprintf(name, sizeof(name), "%s_%d", class_name(), dd->unit);
+ snprintf(name, sizeof(name), "hfi1_%d", dd->unit);
ret = hfi1_cdev_init(dd->unit, name, &hfi1_file_ops,
&dd->user_cdev, &dd->user_device,
true, &dd->verbs_dev.rdi.ibdev.dev.kobj);
diff --git a/drivers/infiniband/hw/hfi1/init.c b/drivers/infiniband/hw/hfi1/init.c
index fb0a8325a43d..28213ddcf2e9 100644
--- a/drivers/infiniband/hw/hfi1/init.c
+++ b/drivers/infiniband/hw/hfi1/init.c
@@ -1236,7 +1236,7 @@ static struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev,
* to work by setting the name manually here.
*/
ibdev = &dd->verbs_dev.rdi.ibdev;
- dev_set_name(&ibdev->dev, "%s_%d", class_name(), dd->unit);
+ dev_set_name(&ibdev->dev, "hfi1_%d", dd->unit);
strscpy(&ibdev->name, dev_name(&ibdev->dev), IB_DEVICE_NAME_MAX);
/*
@@ -1387,7 +1387,7 @@ static int __init hfi1_mod_init(void)
{
int ret;
- ret = dev_init();
+ ret = hfi1_dev_init();
if (ret)
goto bail;
@@ -1460,7 +1460,7 @@ static int __init hfi1_mod_init(void)
bail_dev:
hfi1_dbg_exit();
- dev_cleanup();
+ hfi1_dev_cleanup();
bail:
return ret;
}
@@ -1479,7 +1479,7 @@ static void __exit hfi1_mod_cleanup(void)
WARN_ON(!xa_empty(&hfi1_dev_table));
dispose_firmware(); /* asymmetric with obtain_firmware() */
- dev_cleanup();
+ hfi1_dev_cleanup();
}
module_exit(hfi1_mod_cleanup);
--
2.39.5