Skip to contentSkip to conversation

isa: Ensure number of irq matches number of base

PATCH In review William Breathitt Gray 2 participants 13 messages Aug 18, 2022 – Sep 15, 2022

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

cover isa: Ensure number of irq matches number of base

Several ISA drivers support IRQ and call devm_request_irq() in their device probe callbacks. These drivers typically provide an "irq" array module parameter, which matches with the respective "base" array module parameter, to specify what IRQ lines are used for each device. To reduce code repetition, a module_isa_driver_with_irq helper macro is introduced providing a check ensuring that the number of "irq" passed to the module matches with the respective number of "base". The relevant ISA drivers are updated accordingly to utilize the new module_isa_driver_with_irq macro.

William Breathitt Gray (6):
isa: Introduce the module_isa_driver_with_irq helper macro
counter: 104-quad-8: Ensure number of irq matches number of base
gpio: 104-dio-48e: Ensure number of irq matches number of base
gpio: 104-idi-48: Ensure number of irq matches number of base
gpio: 104-idio-16: Ensure number of irq matches number of base
gpio: ws16c48: Ensure number of irq matches number of base

 drivers/counter/104-quad-8.c    |  5 ++--
 drivers/gpio/gpio-104-dio-48e.c |  5 ++--
 drivers/gpio/gpio-104-idi-48.c  |  5 ++--
 drivers/gpio/gpio-104-idio-16.c |  5 ++--
 drivers/gpio/gpio-ws16c48.c     |  5 ++--
 include/linux/isa.h             | 52 ++++++++++++++++++++++++++-------
 6 files changed, 57 insertions(+), 20 deletions(-)

base-commit: 568035b01cfb107af8d2e4bd2fb9aea22cf5b868

Signature · 1 line
2.37.2
#1 lore raw

PATCH 1/6 isa: Introduce the module_isa_driver_with_irq helper macro

Several ISA drivers feature IRQ support that can configured via an "irq" array module parameter. This array typically matches directly with the respective "base" array module parameter. To reduce code repetition, a module_isa_driver_with_irq helper macro is introduced to provide a check ensuring that the number of "irq" passed to the module matches with the respective number of "base".

---
 include/linux/isa.h | 52 ++++++++++++++++++++++++++++++++++++---------
 1 file changed, 42 insertions(+), 10 deletions(-)
include/linux/isa.h +42 -10
index e30963190968..4fbbf5e36e08 100644
@@ -38,6 +38,32 @@ static inline void isa_unregister_driver(struct isa_driver *d)
 }
 #endif
 
+#define module_isa_driver_init(__isa_driver, __num_isa_dev) \
+static int __init __isa_driver##_init(void) \
+{ \
+	return isa_register_driver(&(__isa_driver), __num_isa_dev); \
+} \
+module_init(__isa_driver##_init)
+
+#define module_isa_driver_with_irq_init(__isa_driver, __num_isa_dev, __num_irq) \
+static int __init __isa_driver##_init(void) \
+{ \
+	if (__num_irq != __num_isa_dev) { \
+		pr_err("%s: Number of irq (%u) does not match number of base (%u)\n", \
+		       __isa_driver.driver.name, __num_irq, __num_isa_dev); \
+		return -EINVAL; \
+	} \
+	return isa_register_driver(&(__isa_driver), __num_isa_dev); \
+} \
+module_init(__isa_driver##_init)
+
+#define module_isa_driver_exit(__isa_driver) \
+static void __exit __isa_driver##_exit(void) \
+{ \
+	isa_unregister_driver(&(__isa_driver)); \
+} \
+module_exit(__isa_driver##_exit)
+
 /**
  * module_isa_driver() - Helper macro for registering a ISA driver
  * @__isa_driver: isa_driver struct
@@ -48,16 +74,22 @@ static inline void isa_unregister_driver(struct isa_driver *d)
  * use this macro once, and calling it replaces module_init and module_exit.
  */
 #define module_isa_driver(__isa_driver, __num_isa_dev) \
-static int __init __isa_driver##_init(void) \
-{ \
-	return isa_register_driver(&(__isa_driver), __num_isa_dev); \
-} \
-module_init(__isa_driver##_init); \
-static void __exit __isa_driver##_exit(void) \
-{ \
-	isa_unregister_driver(&(__isa_driver)); \
-} \
-module_exit(__isa_driver##_exit);
+module_isa_driver_init(__isa_driver, __num_isa_dev); \
+module_isa_driver_exit(__isa_driver)
+
+/**
+ * module_isa_driver_with_irq() - Helper macro for registering an ISA driver with irq
+ * @__isa_driver: isa_driver struct
+ * @__num_isa_dev: number of devices to register
+ * @__num_irq: number of IRQ to register
+ *
+ * Helper macro for ISA drivers with irq that do not do anything special in
+ * module init/exit. Each module may only use this macro once, and calling it
+ * replaces module_init and module_exit.
+ */
+#define module_isa_driver_with_irq(__isa_driver, __num_isa_dev, __num_irq) \
+module_isa_driver_with_irq_init(__isa_driver, __num_isa_dev, __num_irq); \
+module_isa_driver_exit(__isa_driver)
 
 /**
  * max_num_isa_dev() - Maximum possible number registered of an ISA device
Signature · 1 line
2.37.2
author Acked-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] isa: Introduce the module_isa_driver_with_irq helper macro

Quoted 8 lines · William Breathitt Gray

Several ISA drivers feature IRQ support that can configured via an "irq" array module parameter. This array typically matches directly with the respective "base" array module parameter. To reduce code repetition, a module_isa_driver_with_irq helper macro is introduced to provide a check ensuring that the number of "irq" passed to the module matches with the respective number of "base".

#3 lore raw

Re: [PATCH 1/6] isa: Introduce the module_isa_driver_with_irq helper macro

Quoted 9 lines · William Breathitt Gray
Quoted 7 lines · William Breathitt Gray

Several ISA drivers feature IRQ support that can configured via an "irq" array module parameter. This array typically matches directly with the respective "base" array module parameter. To reduce code repetition, a module_isa_driver_with_irq helper macro is introduced to provide a check ensuring that the number of "irq" passed to the module matches with the respective number of "base".

Quoted 3 lines
Quoted 1 line

Series queued.

Bart

#4 lore raw

PATCH 2/6 counter: 104-quad-8: Ensure number of irq matches number of base

In reply to William Breathitt Gray

The 104-quad-8 module calls devm_request_irq() for each device. If the number of irq passed to the module does not match the number of base, a default value of 0 is passed to devm_request_irq(). IRQ 0 is probably not what the user wants, so utilize the module_isa_driver_with_irq macro to ensure the number of irq matches the number of base.

---
 drivers/counter/104-quad-8.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/counter/104-quad-8.c +3 -2
index 62c2b7ac4339..3f8d1910a9bb 100644
@@ -28,7 +28,8 @@ module_param_hw_array(base, uint, ioport, &num_quad8, 0);
 MODULE_PARM_DESC(base, "ACCES 104-QUAD-8 base addresses");
 
 static unsigned int irq[max_num_isa_dev(QUAD8_EXTENT)];
-module_param_hw_array(irq, uint, irq, NULL, 0);
+static unsigned int num_irq;
+module_param_hw_array(irq, uint, irq, &num_irq, 0);
 MODULE_PARM_DESC(irq, "ACCES 104-QUAD-8 interrupt line numbers");
 
 #define QUAD8_NUM_COUNTERS 8
@@ -1236,7 +1237,7 @@ static struct isa_driver quad8_driver = {
 	}
 };
 
-module_isa_driver(quad8_driver, num_quad8);
+module_isa_driver_with_irq(quad8_driver, num_quad8, num_irq);
 
 MODULE_AUTHOR("William Breathitt Gray <[email protected]>");
 MODULE_DESCRIPTION("ACCES 104-QUAD-8 driver");
Signature · 1 line
2.37.2
author Acked-by on v1 2/6
#5 lore raw

Re: [PATCH 2/6] counter: 104-quad-8: Ensure number of irq matches number of base

Quoted 7 lines · William Breathitt Gray

The 104-quad-8 module calls devm_request_irq() for each device. If the number of irq passed to the module does not match the number of base, a default value of 0 is passed to devm_request_irq(). IRQ 0 is probably not what the user wants, so utilize the module_isa_driver_with_irq macro to ensure the number of irq matches the number of base.

#6 lore raw

PATCH 3/6 gpio: 104-dio-48e: Ensure number of irq matches number of base

In reply to William Breathitt Gray

The 104-dio-48e module calls devm_request_irq() for each device. If the number of irq passed to the module does not match the number of base, a default value of 0 is passed to devm_request_irq(). IRQ 0 is probably not what the user wants, so utilize the module_isa_driver_with_irq macro to ensure the number of irq matches the number of base.

---
 drivers/gpio/gpio-104-dio-48e.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpio/gpio-104-dio-48e.c +3 -2
index a41551870759..8b5172802188 100644
@@ -34,7 +34,8 @@ module_param_hw_array(base, uint, ioport, &num_dio48e, 0);
 MODULE_PARM_DESC(base, "ACCES 104-DIO-48E base addresses");
 
 static unsigned int irq[MAX_NUM_DIO48E];
-module_param_hw_array(irq, uint, irq, NULL, 0);
+static unsigned int num_irq;
+module_param_hw_array(irq, uint, irq, &num_irq, 0);
 MODULE_PARM_DESC(irq, "ACCES 104-DIO-48E interrupt line numbers");
 
 #define DIO48E_NUM_PPI 2
@@ -358,7 +359,7 @@ static struct isa_driver dio48e_driver = {
 		.name = "104-dio-48e"
 	},
 };
-module_isa_driver(dio48e_driver, num_dio48e);
+module_isa_driver_with_irq(dio48e_driver, num_dio48e, num_irq);
 
 MODULE_AUTHOR("William Breathitt Gray <[email protected]>");
 MODULE_DESCRIPTION("ACCES 104-DIO-48E GPIO driver");
Signature · 1 line
2.37.2
#7 lore raw

PATCH 4/6 gpio: 104-idi-48: Ensure number of irq matches number of base

In reply to William Breathitt Gray

The 104-idi-48 module calls devm_request_irq() for each device. If the number of irq passed to the module does not match the number of base, a default value of 0 is passed to devm_request_irq(). IRQ 0 is probably not what the user wants, so utilize the module_isa_driver_with_irq macro to ensure the number of irq matches the number of base.

---
 drivers/gpio/gpio-104-idi-48.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpio/gpio-104-idi-48.c +3 -2
index 40be76efeed7..2b0256eefb70 100644
@@ -34,7 +34,8 @@ module_param_hw_array(base, uint, ioport, &num_idi_48, 0);
 MODULE_PARM_DESC(base, "ACCES 104-IDI-48 base addresses");
 
 static unsigned int irq[MAX_NUM_IDI_48];
-module_param_hw_array(irq, uint, irq, NULL, 0);
+static unsigned int num_irq;
+module_param_hw_array(irq, uint, irq, &num_irq, 0);
 MODULE_PARM_DESC(irq, "ACCES 104-IDI-48 interrupt line numbers");
 
 /**
@@ -300,7 +301,7 @@ static struct isa_driver idi_48_driver = {
 		.name = "104-idi-48"
 	},
 };
-module_isa_driver(idi_48_driver, num_idi_48);
+module_isa_driver_with_irq(idi_48_driver, num_idi_48, num_irq);
 
 MODULE_AUTHOR("William Breathitt Gray <[email protected]>");
 MODULE_DESCRIPTION("ACCES 104-IDI-48 GPIO driver");
Signature · 1 line
2.37.2
#8 lore raw

PATCH 5/6 gpio: 104-idio-16: Ensure number of irq matches number of base

In reply to William Breathitt Gray

The 104-idio-16 module calls devm_request_irq() for each device. If the number of irq passed to the module does not match the number of base, a default value of 0 is passed to devm_request_irq(). IRQ 0 is probably not what the user wants, so utilize the module_isa_driver_with_irq macro to ensure the number of irq matches the number of base.

---
 drivers/gpio/gpio-104-idio-16.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpio/gpio-104-idio-16.c +3 -2
index 65a5f581d981..73d95b55a8c5 100644
@@ -30,7 +30,8 @@ module_param_hw_array(base, uint, ioport, &num_idio_16, 0);
 MODULE_PARM_DESC(base, "ACCES 104-IDIO-16 base addresses");
 
 static unsigned int irq[MAX_NUM_IDIO_16];
-module_param_hw_array(irq, uint, irq, NULL, 0);
+static unsigned int num_irq;
+module_param_hw_array(irq, uint, irq, &num_irq, 0);
 MODULE_PARM_DESC(irq, "ACCES 104-IDIO-16 interrupt line numbers");
 
 /**
@@ -333,7 +334,7 @@ static struct isa_driver idio_16_driver = {
 	},
 };
 
-module_isa_driver(idio_16_driver, num_idio_16);
+module_isa_driver_with_irq(idio_16_driver, num_idio_16, num_irq);
 
 MODULE_AUTHOR("William Breathitt Gray <[email protected]>");
 MODULE_DESCRIPTION("ACCES 104-IDIO-16 GPIO driver");
Signature · 1 line
2.37.2
#9 lore raw

PATCH 6/6 gpio: ws16c48: Ensure number of irq matches number of base

In reply to William Breathitt Gray

The ws16c48 module calls devm_request_irq() for each device. If the number of irq passed to the module does not match the number of base, a default value of 0 is passed to devm_request_irq(). IRQ 0 is probably not what the user wants, so utilize the module_isa_driver_with_irq macro to ensure the number of irq matches the number of base.

---
 drivers/gpio/gpio-ws16c48.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpio/gpio-ws16c48.c +3 -2
index b098f2dc196b..88410da91aaf 100644
@@ -27,7 +27,8 @@ module_param_hw_array(base, uint, ioport, &num_ws16c48, 0);
 MODULE_PARM_DESC(base, "WinSystems WS16C48 base addresses");
 
 static unsigned int irq[MAX_NUM_WS16C48];
-module_param_hw_array(irq, uint, irq, NULL, 0);
+static unsigned int num_irq;
+module_param_hw_array(irq, uint, irq, &num_irq, 0);
 MODULE_PARM_DESC(irq, "WinSystems WS16C48 interrupt line numbers");
 
 /**
@@ -497,7 +498,7 @@ static struct isa_driver ws16c48_driver = {
 	},
 };
 
-module_isa_driver(ws16c48_driver, num_ws16c48);
+module_isa_driver_with_irq(ws16c48_driver, num_ws16c48, num_irq);
 
 MODULE_AUTHOR("William Breathitt Gray <[email protected]>");
 MODULE_DESCRIPTION("WinSystems WS16C48 GPIO driver");
Signature · 1 line
2.37.2
#10 lore raw
In reply to William Breathitt Gray
Quoted 28 lines · William Breathitt Gray

Several ISA drivers support IRQ and call devm_request_irq() in their device probe callbacks. These drivers typically provide an "irq" array module parameter, which matches with the respective "base" array module parameter, to specify what IRQ lines are used for each device. To reduce code repetition, a module_isa_driver_with_irq helper macro is introduced providing a check ensuring that the number of "irq" passed to the module matches with the respective number of "base". The relevant ISA drivers are updated accordingly to utilize the new module_isa_driver_with_irq macro.

William Breathitt Gray (6):
isa: Introduce the module_isa_driver_with_irq helper macro
counter: 104-quad-8: Ensure number of irq matches number of base
gpio: 104-dio-48e: Ensure number of irq matches number of base
gpio: 104-idi-48: Ensure number of irq matches number of base
gpio: 104-idio-16: Ensure number of irq matches number of base
gpio: ws16c48: Ensure number of irq matches number of base

 drivers/counter/104-quad-8.c    |  5 ++--
 drivers/gpio/gpio-104-dio-48e.c |  5 ++--
 drivers/gpio/gpio-104-idi-48.c  |  5 ++--
 drivers/gpio/gpio-104-idio-16.c |  5 ++--
 drivers/gpio/gpio-ws16c48.c     |  5 ++--
 include/linux/isa.h             | 52 ++++++++++++++++++++++++++-------
 6 files changed, 57 insertions(+), 20 deletions(-)
Quoted 4 lines

base-commit: 568035b01cfb107af8d2e4bd2fb9aea22cf5b868 --
2.37.2

Looks good to me, do you send your PRs directly to Linus? Do you want me to take this through the GPIO tree?

Bart

#11 lore raw
Quoted 35 lines · Bartosz Golaszewski
Quoted 28 lines · William Breathitt Gray

Several ISA drivers support IRQ and call devm_request_irq() in their device probe callbacks. These drivers typically provide an "irq" array module parameter, which matches with the respective "base" array module parameter, to specify what IRQ lines are used for each device. To reduce code repetition, a module_isa_driver_with_irq helper macro is introduced providing a check ensuring that the number of "irq" passed to the module matches with the respective number of "base". The relevant ISA drivers are updated accordingly to utilize the new module_isa_driver_with_irq macro.

William Breathitt Gray (6):
isa: Introduce the module_isa_driver_with_irq helper macro
counter: 104-quad-8: Ensure number of irq matches number of base
gpio: 104-dio-48e: Ensure number of irq matches number of base
gpio: 104-idi-48: Ensure number of irq matches number of base
gpio: 104-idio-16: Ensure number of irq matches number of base
gpio: ws16c48: Ensure number of irq matches number of base

 drivers/counter/104-quad-8.c    |  5 ++--
 drivers/gpio/gpio-104-dio-48e.c |  5 ++--
 drivers/gpio/gpio-104-idi-48.c  |  5 ++--
 drivers/gpio/gpio-104-idio-16.c |  5 ++--
 drivers/gpio/gpio-ws16c48.c     |  5 ++--
 include/linux/isa.h             | 52 ++++++++++++++++++++++++++-------
 6 files changed, 57 insertions(+), 20 deletions(-)
Quoted 4 lines

base-commit: 568035b01cfb107af8d2e4bd2fb9aea22cf5b868 --
2.37.2

Quoted 4 lines

Looks good to me, do you send your PRs directly to Linus? Do you want me to take this through the GPIO tree?

Bart

Hi Bart,

Would you take this through the GPIO tree? I'm planning on submitting some more patches later for these GPIO drivers so it will be convenient to keep all these changes within the same tree.

Thanks,

William Breathitt Gray

#12 lore raw
Quoted 44 lines · William Breathitt Gray
Quoted 35 lines · Bartosz Golaszewski
Quoted 28 lines · William Breathitt Gray

Several ISA drivers support IRQ and call devm_request_irq() in their device probe callbacks. These drivers typically provide an "irq" array module parameter, which matches with the respective "base" array module parameter, to specify what IRQ lines are used for each device. To reduce code repetition, a module_isa_driver_with_irq helper macro is introduced providing a check ensuring that the number of "irq" passed to the module matches with the respective number of "base". The relevant ISA drivers are updated accordingly to utilize the new module_isa_driver_with_irq macro.

William Breathitt Gray (6):
isa: Introduce the module_isa_driver_with_irq helper macro
counter: 104-quad-8: Ensure number of irq matches number of base
gpio: 104-dio-48e: Ensure number of irq matches number of base
gpio: 104-idi-48: Ensure number of irq matches number of base
gpio: 104-idio-16: Ensure number of irq matches number of base
gpio: ws16c48: Ensure number of irq matches number of base

 drivers/counter/104-quad-8.c    |  5 ++--
 drivers/gpio/gpio-104-dio-48e.c |  5 ++--
 drivers/gpio/gpio-104-idi-48.c  |  5 ++--
 drivers/gpio/gpio-104-idio-16.c |  5 ++--
 drivers/gpio/gpio-ws16c48.c     |  5 ++--
 include/linux/isa.h             | 52 ++++++++++++++++++++++++++-------
 6 files changed, 57 insertions(+), 20 deletions(-)
Quoted 4 lines

base-commit: 568035b01cfb107af8d2e4bd2fb9aea22cf5b868 --
2.37.2

Quoted 4 lines

Looks good to me, do you send your PRs directly to Linus? Do you want me to take this through the GPIO tree?

Bart

Hi Bart,

Quoted 7 lines

Would you take this through the GPIO tree? I'm planning on submitting some more patches later for these GPIO drivers so it will be convenient to keep all these changes within the same tree.

Thanks,

William Breathitt Gray

Sure, just leave your Acks on the first two patches.

Bart