Skip to contentSkip to conversation

driver core: auxiliary bus: Fix sysfs creation on bind

PATCH Superseded Tariq Toukan 4 participants 7 messages Oct 23, 2025 – Oct 26, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 driver core: auxiliary bus: Fix sysfs creation on bind

From: Amir Tzin <[email protected]>

In case an auxiliary device with IRQs directory is unbinded, the directory is released, but auxdev->sysfs.irq_dir_exists remains true. This leads to a failure recreating the directory on bind [1].

Using the attributes group visibility interface, expose the IRQs attributes group if"f the xarray storing IRQs entries is not empty. Now irq_dir_exists field is redundant and can be removed.

[1]
[] mlx5_core.sf mlx5_core.sf.2: mlx5_irq_affinity_request:167:(pid 1939):
Failed to create sysfs entry for irq 56, ret = -2
[] mlx5_core.sf mlx5_core.sf.2: mlx5_eq_table_create:1195:(pid 1939):
Failed to create async EQs
[] mlx5_core.sf mlx5_core.sf.2: mlx5_load:1362:(pid 1939):
Failed to create EQs

Fixes a808878308a8 ("driver core: auxiliary bus: show auxiliary device IRQs")
---
 drivers/base/auxiliary.c       |  13 +++-
 drivers/base/auxiliary_sysfs.c | 117 +++++++++++++++++++++++++--------
 include/linux/auxiliary_bus.h  |  26 ++++++--
 3 files changed, 118 insertions(+), 38 deletions(-)
drivers/base/auxiliary.c +11 -2
index 04bdbff4dbe5..b0fb31279257 100644
@@ -225,7 +225,16 @@ static int auxiliary_bus_probe(struct device *dev)
 		return ret;
 	}
 
-	return auxdrv->probe(auxdev, auxiliary_match_id(auxdrv->id_table, auxdev));
+	ret = auxiliary_bus_irq_dir_res_probe(auxdev);
+	if  (ret)
+		return ret;
+
+	ret = auxdrv->probe(auxdev,
+			    auxiliary_match_id(auxdrv->id_table, auxdev));
+	if (ret)
+		auxiliary_bus_irq_dir_res_remove(auxdev);
+
+	return ret;
 }
 
 static void auxiliary_bus_remove(struct device *dev)
@@ -235,6 +244,7 @@ static void auxiliary_bus_remove(struct device *dev)
 
 	if (auxdrv->remove)
 		auxdrv->remove(auxdev);
+	auxiliary_bus_irq_dir_res_remove(auxdev);
 }
 
 static void auxiliary_bus_shutdown(struct device *dev)
@@ -294,7 +304,6 @@ int auxiliary_device_init(struct auxiliary_device *auxdev)
 
 	dev->bus = &auxiliary_bus_type;
 	device_initialize(&auxdev->dev);
-	mutex_init(&auxdev->sysfs.lock);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(auxiliary_device_init);
drivers/base/auxiliary_sysfs.c +88 -29

171 lines not on this page · raw message

include/linux/auxiliary_bus.h +19 -7
index 4086afd0cc6b..06c247b647ab 100644
@@ -61,7 +61,6 @@
  * @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,
- * @sysfs.irq_dir_exists: whether "irqs" directory exists,
  *
  * An auxiliary_device represents a part of its parent device's functionality.
  * It is given a name that, combined with the registering drivers
@@ -146,7 +145,6 @@ struct auxiliary_device {
 	struct {
 		struct xarray irqs;
 		struct mutex lock; /* Synchronize irq sysfs creation */
-		bool irq_dir_exists;
 	} sysfs;
 };
 
@@ -222,23 +220,37 @@ int __auxiliary_device_add(struct auxiliary_device *auxdev, const char *modname)
 #define auxiliary_device_add(auxdev) __auxiliary_device_add(auxdev, KBUILD_MODNAME)
 
 #ifdef CONFIG_SYSFS
+void auxiliary_bus_irq_dir_res_remove(struct auxiliary_device *auxdev);
+int auxiliary_bus_irq_dir_res_probe(struct auxiliary_device *auxdev);
 int auxiliary_device_sysfs_irq_add(struct auxiliary_device *auxdev, int irq);
-void auxiliary_device_sysfs_irq_remove(struct auxiliary_device *auxdev,
-				       int irq);
+int auxiliary_device_sysfs_irq_remove(struct auxiliary_device *auxdev, int irq);
 #else /* CONFIG_SYSFS */
+static inline void
+auxiliary_bus_irq_dir_res_remove(struct auxiliary_device *auxdev)
+{
+}
+
+static inline int
+auxiliary_bus_irq_dir_res_probe(struct auxiliary_device *auxdev)
+{
+	return 0;
+}
+
 static inline int
 auxiliary_device_sysfs_irq_add(struct auxiliary_device *auxdev, int irq)
 {
 	return 0;
 }
 
-static inline void
-auxiliary_device_sysfs_irq_remove(struct auxiliary_device *auxdev, int irq) {}
+static inline int
+auxiliary_device_sysfs_irq_remove(struct auxiliary_device *auxdev, int irq)
+{
+	return 0;
+}
 #endif
 
 static inline void auxiliary_device_uninit(struct auxiliary_device *auxdev)
 {
-	mutex_destroy(&auxdev->sysfs.lock);
 	put_device(&auxdev->dev);
 }
 

base-commit: c0178eec8884231a5ae0592b9fce827bccb77e86

Signature · 1 line
2.31.1
#1 lore raw
Quoted 33 lines · Tariq Toukan

From: Amir Tzin <[email protected]>

In case an auxiliary device with IRQs directory is unbinded, the directory is released, but auxdev->sysfs.irq_dir_exists remains true. This leads to a failure recreating the directory on bind [1].

Using the attributes group visibility interface, expose the IRQs attributes group if"f the xarray storing IRQs entries is not empty. Now irq_dir_exists field is redundant and can be removed.

[1]
[] mlx5_core.sf mlx5_core.sf.2: mlx5_irq_affinity_request:167:(pid 1939):
Failed to create sysfs entry for irq 56, ret = -2
[] mlx5_core.sf mlx5_core.sf.2: mlx5_eq_table_create:1195:(pid 1939):
Failed to create async EQs
[] mlx5_core.sf mlx5_core.sf.2: mlx5_load:1362:(pid 1939):
Failed to create EQs

Fixes a808878308a8 ("driver core: auxiliary bus: show auxiliary device IRQs")
---
 drivers/base/auxiliary.c       |  13 +++-
 drivers/base/auxiliary_sysfs.c | 117 +++++++++++++++++++++++++--------
 include/linux/auxiliary_bus.h  |  26 ++++++--
 3 files changed, 118 insertions(+), 38 deletions(-)
drivers/base/auxiliary.c +0 -0
index 04bdbff4dbe5..b0fb31279257 100644

drivers/base/auxiliary.c static int auxiliary_bus_probe(struct device *dev) · line 230

Quoted 7 lines
drivers/base/auxiliary.c +3 -1
@@ -225,7 +225,16 @@ static int auxiliary_bus_probe(struct device *dev)
 		return ret;
 	}
 
-	return auxdrv->probe(auxdev, auxiliary_match_id(auxdrv->id_table, auxdev));
+	ret = auxiliary_bus_irq_dir_res_probe(auxdev);
+	if  (ret)
+		return ret;

Please always use scripts/checkpatch.pl so that you don't get grumpy maintainers asking you why you didn't use scripts/checkpatch.pl...

thanks!

greg k-h

#2 lore raw
Quoted 37 lines · Greg Kroah-Hartman
Quoted 36 lines · Tariq Toukan

From: Amir Tzin <[email protected]>

In case an auxiliary device with IRQs directory is unbinded, the directory is released, but auxdev->sysfs.irq_dir_exists remains true. This leads to a failure recreating the directory on bind [1].

Using the attributes group visibility interface, expose the IRQs attributes group if"f the xarray storing IRQs entries is not empty. Now irq_dir_exists field is redundant and can be removed.

[1]
[] mlx5_core.sf mlx5_core.sf.2: mlx5_irq_affinity_request:167:(pid 1939):
Failed to create sysfs entry for irq 56, ret = -2
[] mlx5_core.sf mlx5_core.sf.2: mlx5_eq_table_create:1195:(pid 1939):
Failed to create async EQs
[] mlx5_core.sf mlx5_core.sf.2: mlx5_load:1362:(pid 1939):
Failed to create EQs

Fixes a808878308a8 ("driver core: auxiliary bus: show auxiliary device IRQs")
---
  drivers/base/auxiliary.c       |  13 +++-
  drivers/base/auxiliary_sysfs.c | 117 +++++++++++++++++++++++++--------
  include/linux/auxiliary_bus.h  |  26 ++++++--
  3 files changed, 118 insertions(+), 38 deletions(-)
drivers/base/auxiliary.c +0 -0
index 04bdbff4dbe5..b0fb31279257 100644
@@ -225,7 +225,16 @@ static int auxiliary_bus_probe(struct device *dev)
  		return ret;
  	}
 
Quoted 8 lines

drivers/base/auxiliary.c static int auxiliary_bus_probe(struct device *dev) · line 230

Quoted 4 lines
drivers/base/auxiliary.c +3 -1
-	return auxdrv->probe(auxdev, auxiliary_match_id(auxdrv->id_table, auxdev));
+	ret = auxiliary_bus_irq_dir_res_probe(auxdev);
+	if  (ret)
+		return ret;

Please always use scripts/checkpatch.pl so that you don't get grumpy maintainers asking you why you didn't use scripts/checkpatch.pl...

Sure. Always running it before submissions.
It passes for me. Anything I miss?

total: 0 errors, 0 warnings, 258 lines checked
patch has no obvious style problems and is ready for submission.

#3 lore raw
Quoted 48 lines · Tariq Toukan
Quoted 29 lines · Greg Kroah-Hartman
Quoted 28 lines · Tariq Toukan

From: Amir Tzin <[email protected]>

In case an auxiliary device with IRQs directory is unbinded, the directory is released, but auxdev->sysfs.irq_dir_exists remains true. This leads to a failure recreating the directory on bind [1].

Using the attributes group visibility interface, expose the IRQs attributes group if"f the xarray storing IRQs entries is not empty. Now irq_dir_exists field is redundant and can be removed.

[1]
[] mlx5_core.sf mlx5_core.sf.2: mlx5_irq_affinity_request:167:(pid 1939):
Failed to create sysfs entry for irq 56, ret = -2
[] mlx5_core.sf mlx5_core.sf.2: mlx5_eq_table_create:1195:(pid 1939):
Failed to create async EQs
[] mlx5_core.sf mlx5_core.sf.2: mlx5_load:1362:(pid 1939):
Failed to create EQs

Fixes a808878308a8 ("driver core: auxiliary bus: show auxiliary device IRQs")
---
  drivers/base/auxiliary.c       |  13 +++-
  drivers/base/auxiliary_sysfs.c | 117 +++++++++++++++++++++++++--------
  include/linux/auxiliary_bus.h  |  26 ++++++--
  3 files changed, 118 insertions(+), 38 deletions(-)
Quoted 15 lines

drivers/base/auxiliary.c static int auxiliary_bus_probe(struct device *dev) · line 229

Quoted 11 lines
drivers/base/auxiliary.c +3 -1
index 04bdbff4dbe5..b0fb31279257 100644
@@ -225,7 +225,16 @@ static int auxiliary_bus_probe(struct device *dev)
  		return ret;
  	}
-	return auxdrv->probe(auxdev, auxiliary_match_id(auxdrv->id_table, auxdev));
+	ret = auxiliary_bus_irq_dir_res_probe(auxdev);
+	if  (ret)
+		return ret;

Please always use scripts/checkpatch.pl so that you don't get grumpy maintainers asking you why you didn't use scripts/checkpatch.pl...

Quoted 5 lines

Sure. Always running it before submissions.
It passes for me. Anything I miss?

total: 0 errors, 0 warnings, 258 lines checked
patch has no obvious style problems and is ready for submission.

Odd, why did it not catch that extra ' ' after the "if"?

thanks,

greg k-h

#4 lore raw
In reply to Tariq Toukan
Quoted 18 lines · Tariq Toukan

From: Amir Tzin <[email protected]>

In case an auxiliary device with IRQs directory is unbinded, the directory is released, but auxdev->sysfs.irq_dir_exists remains true. This leads to a failure recreating the directory on bind [1].

Using the attributes group visibility interface, expose the IRQs attributes group if"f the xarray storing IRQs entries is not empty. Now irq_dir_exists field is redundant and can be removed.

[1]
[] mlx5_core.sf mlx5_core.sf.2: mlx5_irq_affinity_request:167:(pid 1939):
Failed to create sysfs entry for irq 56, ret = -2
[] mlx5_core.sf mlx5_core.sf.2: mlx5_eq_table_create:1195:(pid 1939):
Failed to create async EQs
[] mlx5_core.sf mlx5_core.sf.2: mlx5_load:1362:(pid 1939):
Failed to create EQs

Quoted 8 lines
Fixes a808878308a8 ("driver core: auxiliary bus: show auxiliary device IRQs")
---
 drivers/base/auxiliary.c       |  13 +++-
 drivers/base/auxiliary_sysfs.c | 117 +++++++++++++++++++++++++--------
 include/linux/auxiliary_bus.h  |  26 ++++++--

Why would auxbus patches go through the net tree?

confused,

greg k-h

#5 lore raw
Quoted 28 lines · Greg Kroah-Hartman
Quoted 18 lines · Tariq Toukan

From: Amir Tzin <[email protected]>

In case an auxiliary device with IRQs directory is unbinded, the directory is released, but auxdev->sysfs.irq_dir_exists remains true. This leads to a failure recreating the directory on bind [1].

Using the attributes group visibility interface, expose the IRQs attributes group if"f the xarray storing IRQs entries is not empty. Now irq_dir_exists field is redundant and can be removed.

[1]
[] mlx5_core.sf mlx5_core.sf.2: mlx5_irq_affinity_request:167:(pid 1939):
Failed to create sysfs entry for irq 56, ret = -2
[] mlx5_core.sf mlx5_core.sf.2: mlx5_eq_table_create:1195:(pid 1939):
Failed to create async EQs
[] mlx5_core.sf mlx5_core.sf.2: mlx5_load:1362:(pid 1939):
Failed to create EQs

Quoted 8 lines
Fixes a808878308a8 ("driver core: auxiliary bus: show auxiliary device IRQs")
---
  drivers/base/auxiliary.c       |  13 +++-
  drivers/base/auxiliary_sysfs.c | 117 +++++++++++++++++++++++++--------
  include/linux/auxiliary_bus.h  |  26 ++++++--
Quoted 2 lines

Why would auxbus patches go through the net tree?

It shouldn't...
Honest mistake passing the argument to my script.

#6 lore raw
In reply to Tariq Toukan
Quoted 8 lines · Tariq Toukan

From: Amir Tzin <[email protected]>

In case an auxiliary device with IRQs directory is unbinded, the directory is released, but auxdev->sysfs.irq_dir_exists remains true. This leads to a failure recreating the directory on bind [1].

Using the attributes group visibility interface, expose the IRQs attributes group if"f the xarray storing IRQs entries is not empty. Now

if"f -> if

Quoted 29 lines

irq_dir_exists field is redundant and can be removed.

[1]
[] mlx5_core.sf mlx5_core.sf.2: mlx5_irq_affinity_request:167:(pid 1939):
Failed to create sysfs entry for irq 56, ret = -2
[] mlx5_core.sf mlx5_core.sf.2: mlx5_eq_table_create:1195:(pid 1939):
Failed to create async EQs
[] mlx5_core.sf mlx5_core.sf.2: mlx5_load:1362:(pid 1939):
Failed to create EQs

Fixes a808878308a8 ("driver core: auxiliary bus: show auxiliary device IRQs")
---
 drivers/base/auxiliary.c       |  13 +++-
 drivers/base/auxiliary_sysfs.c | 117 +++++++++++++++++++++++++--------
 include/linux/auxiliary_bus.h  |  26 ++++++--
 3 files changed, 118 insertions(+), 38 deletions(-)
drivers/base/auxiliary.c +0 -1
index 04bdbff4dbe5..b0fb31279257 100644
@@ -225,7 +225,16 @@ static int auxiliary_bus_probe(struct device *dev)
 		return ret;
 	}
 
-	return auxdrv->probe(auxdev, auxiliary_match_id(auxdrv->id_table, auxdev));

drivers/base/auxiliary.c static int auxiliary_bus_probe(struct device *dev) · line 237

Quoted 10 lines
drivers/base/auxiliary.c +10 -0
+	ret = auxiliary_bus_irq_dir_res_probe(auxdev);
+	if  (ret)
+		return ret;
+
+	ret = auxdrv->probe(auxdev,
+			    auxiliary_match_id(auxdrv->id_table, auxdev));
+	if (ret)
+		auxiliary_bus_irq_dir_res_remove(auxdev);
+
+	return ret;

return 0;

Quoted 24 lines
drivers/base/auxiliary.c +1 -1
 }
 
 static void auxiliary_bus_remove(struct device *dev)
@@ -235,6 +244,7 @@ static void auxiliary_bus_remove(struct device *dev)
 
 	if (auxdrv->remove)
 		auxdrv->remove(auxdev);
+	auxiliary_bus_irq_dir_res_remove(auxdev);
 }
 
 static void auxiliary_bus_shutdown(struct device *dev)
@@ -294,7 +304,6 @@ int auxiliary_device_init(struct auxiliary_device *auxdev)
 
 	dev->bus = &auxiliary_bus_type;
 	device_initialize(&auxdev->dev);
-	mutex_init(&auxdev->sysfs.lock);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(auxiliary_device_init);
drivers/base/auxiliary_sysfs.c +0 -0
index 754f21730afd..8ae3ec62b3db 100644

drivers/base/auxiliary_sysfs.c struct auxiliary_irq_info { · line 17

Quoted 5 lines
drivers/base/auxiliary_sysfs.c +2 -0
@@ -13,30 +13,71 @@ struct auxiliary_irq_info {
 	char name[AUXILIARY_MAX_IRQ_NAME];
 };
 
+static struct attribute auxiliary_irq_attr = {
+	.mode = 0,

"static" variable is always initialized to 0, there is no need in .mode = 0 line.

drivers/base/auxiliary_sysfs.c struct auxiliary_irq_info { · line 23

Quoted 7 lines
drivers/base/auxiliary_sysfs.c +5 -1
+	.name = "DUMMY",
+};
+
 static struct attribute *auxiliary_irq_attrs[] = {
-	NULL
+	[0] = &auxiliary_irq_attr,
+	[1] = NULL,

Let's use more common pattern - without [x]

Quoted 23 lines
drivers/base/auxiliary_sysfs.c +15 -1
 };
 
+static bool auxiliary_irq_dir_group_visible(struct kobject *kobj)
+{
+	struct auxiliary_device *auxdev;
+	struct device *dev;
+
+	dev = container_of(kobj, struct device, kobj);
+	auxdev = container_of(dev, struct auxiliary_device, dev);
+
+	return !xa_empty(&auxdev->sysfs.irqs);
+}
+
+DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(auxiliary_irq_dir);
+
 static const struct attribute_group auxiliary_irqs_group = {
 	.name = "irqs",
 	.attrs = auxiliary_irq_attrs,
+	.is_visible = SYSFS_GROUP_VISIBLE(auxiliary_irq_dir),
 };
 
-static int auxiliary_irq_dir_prepare(struct auxiliary_device *auxdev)
+void auxiliary_bus_irq_dir_res_remove(struct auxiliary_device *auxdev)

drivers/base/auxiliary_sysfs.c struct auxiliary_irq_info { · line 51

Quoted 10 lines
drivers/base/auxiliary_sysfs.c +4 -4
 {
-	int ret = 0;
+	struct device *dev = &auxdev->dev;
 
-	guard(mutex)(&auxdev->sysfs.lock);
-	if (auxdev->sysfs.irq_dir_exists)
-		return 0;
+	sysfs_remove_group(&dev->kobj, &auxiliary_irqs_group);
+	xa_destroy(&auxdev->sysfs.irqs);
+	mutex_destroy(&auxdev->sysfs.lock);

Actually you don't need extra sysfs.lock mutex and everything can be protected through xarray lock. So instead of two locks, you will have one with proper lifetime.

Quoted 1 line
drivers/base/auxiliary_sysfs.c +1 -0
+}

<...>

drivers/base/auxiliary_sysfs.c struct auxiliary_device { · line 149

Quoted 5 lines
drivers/base/auxiliary_sysfs.c +0 -1
@@ -146,7 +145,6 @@ struct auxiliary_device {
 	struct {
 		struct xarray irqs;
 		struct mutex lock; /* Synchronize irq sysfs creation */
-		bool irq_dir_exists;

"struct mutex lock" can be replaced with xa_lock(&auxdev->sysfs.irqs).

Thanks