lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250728211022.9165-1-sean.anderson@linux.dev>
Date: Mon, 28 Jul 2025 17:10:22 -0400
From: Sean Anderson <sean.anderson@...ux.dev>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Leon Romanovsky <leon@...nel.org>
Cc: Ira Weiny <ira.weiny@...el.com>,
	Danilo Krummrich <dakr@...nel.org>,
	linux-kernel@...r.kernel.org,
	"Rafael J . Wysocki" <rafael@...nel.org>,
	Dave Ertman <david.m.ertman@...el.com>,
	Sean Anderson <sean.anderson@...ux.dev>
Subject: [PATCH] auxiliary: Automatically generate id

As it turns out, ids are not allowed to have semantic meaning. Their
only purpose is to prevent sysfs collisions. To simplify things, just
generate a unique id for each auxiliary device. Remove all references to
filling in the id member of the device.

Signed-off-by: Sean Anderson <sean.anderson@...ux.dev>
---

 drivers/base/auxiliary.c      | 32 +++++++++++++++++++++++---------
 include/linux/auxiliary_bus.h | 26 ++++++++------------------
 2 files changed, 31 insertions(+), 27 deletions(-)

diff --git a/drivers/base/auxiliary.c b/drivers/base/auxiliary.c
index dba7c8e13a53..f66067df03ad 100644
--- a/drivers/base/auxiliary.c
+++ b/drivers/base/auxiliary.c
@@ -264,6 +264,8 @@ static const struct bus_type auxiliary_bus_type = {
 	.pm = &auxiliary_dev_pm_ops,
 };
 
+static DEFINE_IDA(auxiliary_id);
+
 /**
  * auxiliary_device_init - check auxiliary_device and initialize
  * @auxdev: auxiliary device struct
@@ -331,20 +333,37 @@ int __auxiliary_device_add(struct auxiliary_device *auxdev, const char *modname)
 		return -EINVAL;
 	}
 
+	ret = ida_alloc(&auxiliary_id, GFP_KERNEL);
+	if (ret < 0) {
+		dev_err(dev, "auxiliary device id_alloc fauiled: %d\n", ret);
+		return ret;
+	}
+	auxdev->id = ret;
+
 	ret = dev_set_name(dev, "%s.%s.%d", modname, auxdev->name, auxdev->id);
 	if (ret) {
 		dev_err(dev, "auxiliary device dev_set_name failed: %d\n", ret);
+		ida_free(&auxiliary_id, auxdev->id);
 		return ret;
 	}
 
 	ret = device_add(dev);
-	if (ret)
+	if (ret) {
 		dev_err(dev, "adding auxiliary device failed!: %d\n", ret);
+		ida_free(&auxiliary_id, auxdev->id);
+	}
 
 	return ret;
 }
 EXPORT_SYMBOL_GPL(__auxiliary_device_add);
 
+void auxiliary_device_delete(struct auxiliary_device *auxdev)
+{
+	ida_free(&auxiliary_id, auxdev->id);
+	device_del(&auxdev->dev);
+}
+EXPORT_SYMBOL_GPL(auxiliary_device_delete);
+
 /**
  * __auxiliary_driver_register - register a driver for auxiliary bus devices
  * @auxdrv: auxiliary_driver structure
@@ -408,7 +427,6 @@ static void auxiliary_device_release(struct device *dev)
  * @modname: module name used to create the auxiliary driver name.
  * @devname: auxiliary bus device name
  * @platform_data: auxiliary bus device platform data
- * @id: auxiliary bus device id
  *
  * Helper to create an auxiliary bus device.
  * The device created matches driver 'modname.devname' on the auxiliary bus.
@@ -416,8 +434,7 @@ static void auxiliary_device_release(struct device *dev)
 struct auxiliary_device *auxiliary_device_create(struct device *dev,
 						 const char *modname,
 						 const char *devname,
-						 void *platform_data,
-						 int id)
+						 void *platform_data)
 {
 	struct auxiliary_device *auxdev;
 	int ret;
@@ -426,7 +443,6 @@ struct auxiliary_device *auxiliary_device_create(struct device *dev,
 	if (!auxdev)
 		return NULL;
 
-	auxdev->id = id;
 	auxdev->name = devname;
 	auxdev->dev.parent = dev;
 	auxdev->dev.platform_data = platform_data;
@@ -476,7 +492,6 @@ EXPORT_SYMBOL_GPL(auxiliary_device_destroy);
  * @modname: module name used to create the auxiliary driver name.
  * @devname: auxiliary bus device name
  * @platform_data: auxiliary bus device platform data
- * @id: auxiliary bus device id
  *
  * Device managed helper to create an auxiliary bus device.
  * The device created matches driver 'modname.devname' on the auxiliary bus.
@@ -484,13 +499,12 @@ EXPORT_SYMBOL_GPL(auxiliary_device_destroy);
 struct auxiliary_device *__devm_auxiliary_device_create(struct device *dev,
 							const char *modname,
 							const char *devname,
-							void *platform_data,
-							int id)
+							void *platform_data)
 {
 	struct auxiliary_device *auxdev;
 	int ret;
 
-	auxdev = auxiliary_device_create(dev, modname, devname, platform_data, id);
+	auxdev = auxiliary_device_create(dev, modname, devname, platform_data);
 	if (!auxdev)
 		return NULL;
 
diff --git a/include/linux/auxiliary_bus.h b/include/linux/auxiliary_bus.h
index 4086afd0cc6b..c972b5a3c2c4 100644
--- a/include/linux/auxiliary_bus.h
+++ b/include/linux/auxiliary_bus.h
@@ -57,7 +57,7 @@
  *       The release and parent fields of the device structure must be filled
  *       in
  * @name: Match name found by the auxiliary device driver,
- * @id: unique identitier if multiple devices of the same name are exported,
+ * @id: automatically-generated unique identitier,
  * @sysfs: embedded struct which hold all sysfs related fields,
  * @sysfs.irqs: irqs xarray contains irq indices which are used by the device,
  * @sysfs.lock: Synchronize irq sysfs creation,
@@ -74,15 +74,11 @@
  * Registering an auxiliary_device is a three-step process.
  *
  * First, a 'struct auxiliary_device' needs to be defined or allocated for each
- * sub-device desired.  The name, id, dev.release, and dev.parent fields of
- * this structure must be filled in as follows.
+ * sub-device desired.  The name, dev.release, and dev.parent fields of this
+ * structure must be filled in as follows.
  *
  * The 'name' field is to be given a name that is recognized by the auxiliary
- * driver.  If two auxiliary_devices with the same match_name, eg
- * "foo_mod.foo_dev", are registered onto the bus, they must have unique id
- * values (e.g. "x" and "y") so that the registered devices names are
- * "foo_mod.foo_dev.x" and "foo_mod.foo_dev.y".  If match_name + id are not
- * unique, then the device_add fails and generates an error message.
+ * driver.
  *
  * The auxiliary_device.dev.type.release or auxiliary_device.dev.release must
  * be populated with a non-NULL pointer to successfully register the
@@ -113,7 +109,6 @@
  *
  *	// Step 1:
  *	my_aux_dev->name = MY_DEVICE_NAME;
- *	my_aux_dev->id = my_unique_id_alloc(xxx);
  *	my_aux_dev->dev.release = my_aux_dev_release;
  *	my_aux_dev->dev.parent = my_dev;
  *
@@ -242,10 +237,7 @@ static inline void auxiliary_device_uninit(struct auxiliary_device *auxdev)
 	put_device(&auxdev->dev);
 }
 
-static inline void auxiliary_device_delete(struct auxiliary_device *auxdev)
-{
-	device_del(&auxdev->dev);
-}
+void auxiliary_device_delete(struct auxiliary_device *auxdev);
 
 int __auxiliary_driver_register(struct auxiliary_driver *auxdrv, struct module *owner,
 				const char *modname);
@@ -257,19 +249,17 @@ void auxiliary_driver_unregister(struct auxiliary_driver *auxdrv);
 struct auxiliary_device *auxiliary_device_create(struct device *dev,
 						 const char *modname,
 						 const char *devname,
-						 void *platform_data,
-						 int id);
+						 void *platform_data);
 void auxiliary_device_destroy(void *auxdev);
 
 struct auxiliary_device *__devm_auxiliary_device_create(struct device *dev,
 							const char *modname,
 							const char *devname,
-							void *platform_data,
-							int id);
+							void *platform_data);
 
 #define devm_auxiliary_device_create(dev, devname, platform_data)     \
 	__devm_auxiliary_device_create(dev, KBUILD_MODNAME, devname,  \
-				       platform_data, 0)
+				       platform_data)
 
 /**
  * module_auxiliary_driver() - Helper macro for registering an auxiliary driver
-- 
2.35.1.1320.gc452695387.dirty


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ