diff mbox series

[v4,5/7] gpio: gpiolib: Add a check to validate GPIO hwirq

Message ID 20220518192924.20948-6-prabhakar.mahadev-lad.rj@bp.renesas.com (mailing list archive)
State Superseded
Delegated to: Geert Uytterhoeven
Headers show
Series Renesas RZ/G2L IRQC support | expand

Commit Message

Lad Prabhakar May 18, 2022, 7:29 p.m. UTC
Add a check to validate GPIO hwirq is always within the range of hwirq_max
set in the GPIO irq domain.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
---
 drivers/gpio/gpiolib.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Andy Shevchenko May 18, 2022, 9:08 p.m. UTC | #1
On Wed, May 18, 2022 at 9:30 PM Lad Prabhakar
<prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:
>
> Add a check to validate GPIO hwirq is always within the range of hwirq_max
> set in the GPIO irq domain.

...

> +                       if (WARN(hwirq >= domain->hwirq_max,
> +                                "error: hwirq 0x%x is too large for %s\n",
> +                                (int)hwirq, domain->name))

Using castings in the printf() often points to possible mistakes or
missed custom specifiers.

...

> +               if (WARN(hwirq >= domain->hwirq_max,
> +                        "error: hwirq 0x%x is too large for %s\n", (int)hwirq, domain->name))

Ditto.
Prabhakar May 19, 2022, 4:11 a.m. UTC | #2
Hi Andy,

Thank you for the review.

On Wed, May 18, 2022 at 10:08 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Wed, May 18, 2022 at 9:30 PM Lad Prabhakar
> <prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:
> >
> > Add a check to validate GPIO hwirq is always within the range of hwirq_max
> > set in the GPIO irq domain.
>
> ...
>
> > +                       if (WARN(hwirq >= domain->hwirq_max,
> > +                                "error: hwirq 0x%x is too large for %s\n",
> > +                                (int)hwirq, domain->name))
>
> Using castings in the printf() often points to possible mistakes or
> missed custom specifiers.
>
Right, I picked up the printf() just a few lines above where it did
the same exact thing. I will update it in the next version.

> ...
>
> > +               if (WARN(hwirq >= domain->hwirq_max,
> > +                        "error: hwirq 0x%x is too large for %s\n", (int)hwirq, domain->name))
>
> Ditto.
>
Will drop castings.

Cheers,
Prabhakar
diff mbox series

Patch

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 65e344a23c6a..c1de7bb54c13 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1028,6 +1028,7 @@  static void gpiochip_set_hierarchical_irqchip(struct gpio_chip *gc,
 	 * it is necessary to keep this around.
 	 */
 	if (is_fwnode_irqchip(gc->irq.fwnode)) {
+		struct irq_domain *domain = gc->irq.domain;
 		int i;
 		int ret;
 
@@ -1061,6 +1062,11 @@  static void gpiochip_set_hierarchical_irqchip(struct gpio_chip *gc,
 					 i, ret);
 				continue;
 			}
+			if (WARN(hwirq >= domain->hwirq_max,
+				 "error: hwirq 0x%x is too large for %s\n",
+				 (int)hwirq, domain->name))
+				continue;
+
 			fwspec.fwnode = gc->irq.fwnode;
 			/* This is the hwirq for the GPIO line side of things */
 			fwspec.param[0] = hwirq;
@@ -1436,6 +1442,9 @@  static int gpiochip_to_irq(struct gpio_chip *gc, unsigned int offset)
 		ret = gc->irq.child_offset_to_irq(gc, offset, &hwirq);
 		if (ret)
 			return ret;
+		if (WARN(hwirq >= domain->hwirq_max,
+			 "error: hwirq 0x%x is too large for %s\n", (int)hwirq, domain->name))
+			return -EINVAL;
 		spec.fwnode = domain->fwnode;
 		spec.param_count = 2;
 		spec.param[0] = hwirq;