[PATCH 2/2] irqchip/mmp: Avoid overflowing icu_data[]

From: Lubomir Rintel
Date: Wed Feb 19 2020 - 03:00:37 EST


In case someone messes up and adds too many interrupt muxes in the device
tree, icu_data would overflow into things that follow it in bss, likely
mmp_icu2_base and mmp_icu_base.

Let's add a safeguard, so that we fail gracefully instead of panicking
at some later point for reasons that are then not immediately clear.

Signed-off-by: Lubomir Rintel <lkundrak@xxxxx>
---
drivers/irqchip/irq-mmp.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/irqchip/irq-mmp.c b/drivers/irqchip/irq-mmp.c
index f597d96409a1f..c7ef2cea1c020 100644
--- a/drivers/irqchip/irq-mmp.c
+++ b/drivers/irqchip/irq-mmp.c
@@ -505,6 +505,11 @@ static int __init mmp2_mux_of_init(struct device_node *node,
return -ENODEV;

i = max_icu_nr;
+ if (i >= MAX_ICU_NR) {
+ pr_err("Too many interrupt muxes\n");
+ return -EINVAL;
+ }
+
ret = of_property_read_u32(node, "mrvl,intc-nr-irqs",
&nr_irqs);
if (ret) {
--
2.24.1