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
--
2.37.2
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.
Signed-off-by: William Breathitt Gray <[email protected]>
---
drivers/counter/104-quad-8.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
index 62c2b7ac4339..3f8d1910a9bb 100644
--- a/drivers/counter/104-quad-8.c
+++ b/drivers/counter/104-quad-8.c
@@ -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");
--
2.37.2
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.
Signed-off-by: William Breathitt Gray <[email protected]>
---
drivers/gpio/gpio-104-idi-48.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/gpio-104-idi-48.c b/drivers/gpio/gpio-104-idi-48.c
index 40be76efeed7..2b0256eefb70 100644
--- a/drivers/gpio/gpio-104-idi-48.c
+++ b/drivers/gpio/gpio-104-idi-48.c
@@ -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");
--
2.37.2
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.
Signed-off-by: William Breathitt Gray <[email protected]>
---
drivers/gpio/gpio-104-idio-16.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/gpio-104-idio-16.c b/drivers/gpio/gpio-104-idio-16.c
index 65a5f581d981..73d95b55a8c5 100644
--- a/drivers/gpio/gpio-104-idio-16.c
+++ b/drivers/gpio/gpio-104-idio-16.c
@@ -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");
--
2.37.2
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.
Signed-off-by: William Breathitt Gray <[email protected]>
---
drivers/gpio/gpio-104-dio-48e.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/gpio-104-dio-48e.c b/drivers/gpio/gpio-104-dio-48e.c
index a41551870759..8b5172802188 100644
--- a/drivers/gpio/gpio-104-dio-48e.c
+++ b/drivers/gpio/gpio-104-dio-48e.c
@@ -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");
--
2.37.2
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".
Signed-off-by: William Breathitt Gray <[email protected]>
---
include/linux/isa.h | 52 ++++++++++++++++++++++++++++++++++++---------
1 file changed, 42 insertions(+), 10 deletions(-)
diff --git a/include/linux/isa.h b/include/linux/isa.h
index e30963190968..4fbbf5e36e08 100644
--- a/include/linux/isa.h
+++ b/include/linux/isa.h
@@ -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
--
2.37.2
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.
Signed-off-by: William Breathitt Gray <[email protected]>
---
drivers/gpio/gpio-ws16c48.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/gpio-ws16c48.c b/drivers/gpio/gpio-ws16c48.c
index b098f2dc196b..88410da91aaf 100644
--- a/drivers/gpio/gpio-ws16c48.c
+++ b/drivers/gpio/gpio-ws16c48.c
@@ -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");
--
2.37.2
On Fri, Aug 19, 2022 at 1:11 AM William Breathitt Gray
<[email protected]> wrote:
>
> 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
> --
> 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
On Wed, Aug 31, 2022 at 3:54 PM William Breathitt Gray
<[email protected]> wrote:
>
> On Wed, Aug 31, 2022 at 02:35:51PM +0200, Bartosz Golaszewski wrote:
> > On Fri, Aug 19, 2022 at 1:11 AM William Breathitt Gray
> > <[email protected]> wrote:
> > >
> > > 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
> > > --
> > > 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
>
> 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
Sure, just leave your Acks on the first two patches.
Bart
On Wed, Aug 31, 2022 at 02:35:51PM +0200, Bartosz Golaszewski wrote:
> On Fri, Aug 19, 2022 at 1:11 AM William Breathitt Gray
> <[email protected]> wrote:
> >
> > 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
> > --
> > 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
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
On Thu, Aug 18, 2022 at 12:28:10PM -0400, William Breathitt Gray wrote:
> 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".
>
> Signed-off-by: William Breathitt Gray <[email protected]>
Acked-by: William Breathitt Gray <[email protected]>
On Thu, Aug 18, 2022 at 12:28:11PM -0400, William Breathitt Gray wrote:
> 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.
>
> Signed-off-by: William Breathitt Gray <[email protected]>
Acked-by: William Breathitt Gray <[email protected]>
On Thu, Sep 1, 2022 at 12:53 AM William Breathitt Gray
<[email protected]> wrote:
>
> On Thu, Aug 18, 2022 at 12:28:10PM -0400, William Breathitt Gray wrote:
> > 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".
> >
> > Signed-off-by: William Breathitt Gray <[email protected]>
>
> Acked-by: William Breathitt Gray <[email protected]>
Series queued.
Bart