Skip to content

Commit b68d0ff

Browse files
avpatelKAGA-KOKO
authored andcommitted
irqchip/sifive-plic: Use devm_xyz() for managed allocation
Use devm_xyz() for allocations and mappings managed by the Linux device driver framework. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/20240222094006.1030709-4-apatel@ventanamicro.com
1 parent 25d862e commit b68d0ff

File tree

1 file changed

+16
-33
lines changed

1 file changed

+16
-33
lines changed

drivers/irqchip/irq-sifive-plic.c

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -436,39 +436,30 @@ static int plic_probe(struct platform_device *pdev)
436436
plic_quirks = (unsigned long)id->data;
437437
}
438438

439-
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
439+
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
440440
if (!priv)
441441
return -ENOMEM;
442442

443443
priv->dev = dev;
444444
priv->plic_quirks = plic_quirks;
445445

446-
priv->regs = of_iomap(to_of_node(dev->fwnode), 0);
447-
if (WARN_ON(!priv->regs)) {
448-
error = -EIO;
449-
goto out_free_priv;
450-
}
446+
priv->regs = devm_platform_ioremap_resource(pdev, 0);
447+
if (WARN_ON(!priv->regs))
448+
return -EIO;
451449

452-
error = -EINVAL;
453450
of_property_read_u32(to_of_node(dev->fwnode), "riscv,ndev", &nr_irqs);
454451
if (WARN_ON(!nr_irqs))
455-
goto out_iounmap;
452+
return -EINVAL;
456453

457454
priv->nr_irqs = nr_irqs;
458455

459-
priv->prio_save = bitmap_alloc(nr_irqs, GFP_KERNEL);
456+
priv->prio_save = devm_bitmap_zalloc(dev, nr_irqs, GFP_KERNEL);
460457
if (!priv->prio_save)
461-
goto out_free_priority_reg;
458+
return -ENOMEM;
462459

463460
nr_contexts = of_irq_count(to_of_node(dev->fwnode));
464461
if (WARN_ON(!nr_contexts))
465-
goto out_free_priority_reg;
466-
467-
error = -ENOMEM;
468-
priv->irqdomain = irq_domain_add_linear(to_of_node(dev->fwnode), nr_irqs + 1,
469-
&plic_irqdomain_ops, priv);
470-
if (WARN_ON(!priv->irqdomain))
471-
goto out_free_priority_reg;
462+
return -EINVAL;
472463

473464
for (i = 0; i < nr_contexts; i++) {
474465
struct of_phandle_args parent;
@@ -539,10 +530,10 @@ static int plic_probe(struct platform_device *pdev)
539530
i * CONTEXT_ENABLE_SIZE;
540531
handler->priv = priv;
541532

542-
handler->enable_save = kcalloc(DIV_ROUND_UP(nr_irqs, 32),
543-
sizeof(*handler->enable_save), GFP_KERNEL);
533+
handler->enable_save = devm_kcalloc(dev, DIV_ROUND_UP(nr_irqs, 32),
534+
sizeof(*handler->enable_save), GFP_KERNEL);
544535
if (!handler->enable_save)
545-
goto out_free_enable_reg;
536+
return -ENOMEM;
546537
done:
547538
for (hwirq = 1; hwirq <= nr_irqs; hwirq++) {
548539
plic_toggle(handler, hwirq, 0);
@@ -552,6 +543,11 @@ static int plic_probe(struct platform_device *pdev)
552543
nr_handlers++;
553544
}
554545

546+
priv->irqdomain = irq_domain_add_linear(to_of_node(dev->fwnode), nr_irqs + 1,
547+
&plic_irqdomain_ops, priv);
548+
if (WARN_ON(!priv->irqdomain))
549+
return -ENOMEM;
550+
555551
/*
556552
* We can have multiple PLIC instances so setup cpuhp state
557553
* and register syscore operations only once after context
@@ -578,19 +574,6 @@ static int plic_probe(struct platform_device *pdev)
578574
dev_info(dev, "mapped %d interrupts with %d handlers for %d contexts.\n",
579575
nr_irqs, nr_handlers, nr_contexts);
580576
return 0;
581-
582-
out_free_enable_reg:
583-
for_each_cpu(cpu, cpu_present_mask) {
584-
handler = per_cpu_ptr(&plic_handlers, cpu);
585-
kfree(handler->enable_save);
586-
}
587-
out_free_priority_reg:
588-
kfree(priv->prio_save);
589-
out_iounmap:
590-
iounmap(priv->regs);
591-
out_free_priv:
592-
kfree(priv);
593-
return error;
594577
}
595578

596579
static struct platform_driver plic_driver = {

0 commit comments

Comments
 (0)