Skip to content

Commit 99ad153

Browse files
alcharkKAGA-KOKO
authored andcommitted
irqchip/irq-vt8500: Use fewer global variables and add error handling
Controller private data doesn't really need to be in a global statically allocated array - kzalloc it per controller instead, keeping only one pointer to the primary controller global. While at that, also add proper error return statuses in the init path and respective cleanup of resources on errors. Signed-off-by: Alexey Charkov <alchark@gmail.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/all/20250506-vt8500-intc-updates-v2-5-a3a0606cf92d@gmail.com
1 parent 49f92d3 commit 99ad153

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

drivers/irqchip/irq-vt8500.c

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ struct vt8500_irq_data {
6464
struct irq_domain *domain; /* Domain for this controller */
6565
};
6666

67-
/* Global variable for accessing io-mem addresses */
68-
static struct vt8500_irq_data intc[VT8500_INTC_MAX];
69-
static u32 active_cnt = 0;
7067
/* Primary interrupt controller data */
7168
static struct vt8500_irq_data *primary_intc;
7269

@@ -203,49 +200,54 @@ static void vt8500_handle_irq_chained(struct irq_desc *desc)
203200
static int __init vt8500_irq_init(struct device_node *node,
204201
struct device_node *parent)
205202
{
206-
int irq, i;
203+
struct vt8500_irq_data *intc;
204+
int irq, i, ret = 0;
207205

208-
if (active_cnt == VT8500_INTC_MAX) {
209-
pr_err("%s: Interrupt controllers > VT8500_INTC_MAX\n",
210-
__func__);
211-
goto out;
212-
}
213-
214-
intc[active_cnt].base = of_iomap(node, 0);
215-
intc[active_cnt].domain = irq_domain_add_linear(node, 64,
216-
&vt8500_irq_domain_ops, &intc[active_cnt]);
206+
intc = kzalloc(sizeof(*intc), GFP_KERNEL);
207+
if (!intc)
208+
return -ENOMEM;
217209

218-
if (!intc[active_cnt].base) {
210+
intc->base = of_iomap(node, 0);
211+
if (!intc->base) {
219212
pr_err("%s: Unable to map IO memory\n", __func__);
220-
goto out;
213+
ret = -ENOMEM;
214+
goto err_free;
221215
}
222216

223-
if (!intc[active_cnt].domain) {
217+
intc->domain = irq_domain_add_linear(node,
218+
64,
219+
&vt8500_irq_domain_ops,
220+
intc);
221+
if (!intc->domain) {
224222
pr_err("%s: Unable to add irq domain!\n", __func__);
225-
goto out;
223+
ret = -ENOMEM;
224+
goto err_unmap;
226225
}
227226

228-
vt8500_init_irq_hw(intc[active_cnt].base);
227+
vt8500_init_irq_hw(intc->base);
229228

230229
pr_info("vt8500-irq: Added interrupt controller\n");
231230

232-
active_cnt++;
233-
234231
/* check if this is a chained controller */
235232
if (of_irq_count(node) != 0) {
236233
for (i = 0; i < of_irq_count(node); i++) {
237234
irq = irq_of_parse_and_map(node, i);
238235
irq_set_chained_handler_and_data(irq, vt8500_handle_irq_chained,
239-
&intc[active_cnt]);
236+
intc);
240237
}
241238

242239
pr_info("vt8500-irq: Enabled slave->parent interrupts\n");
243240
} else {
244-
primary_intc = &intc[active_cnt];
241+
primary_intc = intc;
245242
set_handle_irq(vt8500_handle_irq);
246243
}
247-
out:
248244
return 0;
245+
246+
err_unmap:
247+
iounmap(intc->base);
248+
err_free:
249+
kfree(intc);
250+
return ret;
249251
}
250252

251253
IRQCHIP_DECLARE(vt8500_irq, "via,vt8500-intc", vt8500_irq_init);

0 commit comments

Comments
 (0)