@@ -436,39 +436,30 @@ static int plic_probe(struct platform_device *pdev)
436
436
plic_quirks = (unsigned long )id -> data ;
437
437
}
438
438
439
- priv = kzalloc ( sizeof (* priv ), GFP_KERNEL );
439
+ priv = devm_kzalloc ( dev , sizeof (* priv ), GFP_KERNEL );
440
440
if (!priv )
441
441
return - ENOMEM ;
442
442
443
443
priv -> dev = dev ;
444
444
priv -> plic_quirks = plic_quirks ;
445
445
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 ;
451
449
452
- error = - EINVAL ;
453
450
of_property_read_u32 (to_of_node (dev -> fwnode ), "riscv,ndev" , & nr_irqs );
454
451
if (WARN_ON (!nr_irqs ))
455
- goto out_iounmap ;
452
+ return - EINVAL ;
456
453
457
454
priv -> nr_irqs = nr_irqs ;
458
455
459
- priv -> prio_save = bitmap_alloc ( nr_irqs , GFP_KERNEL );
456
+ priv -> prio_save = devm_bitmap_zalloc ( dev , nr_irqs , GFP_KERNEL );
460
457
if (!priv -> prio_save )
461
- goto out_free_priority_reg ;
458
+ return - ENOMEM ;
462
459
463
460
nr_contexts = of_irq_count (to_of_node (dev -> fwnode ));
464
461
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 ;
472
463
473
464
for (i = 0 ; i < nr_contexts ; i ++ ) {
474
465
struct of_phandle_args parent ;
@@ -539,10 +530,10 @@ static int plic_probe(struct platform_device *pdev)
539
530
i * CONTEXT_ENABLE_SIZE ;
540
531
handler -> priv = priv ;
541
532
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 );
544
535
if (!handler -> enable_save )
545
- goto out_free_enable_reg ;
536
+ return - ENOMEM ;
546
537
done :
547
538
for (hwirq = 1 ; hwirq <= nr_irqs ; hwirq ++ ) {
548
539
plic_toggle (handler , hwirq , 0 );
@@ -552,6 +543,11 @@ static int plic_probe(struct platform_device *pdev)
552
543
nr_handlers ++ ;
553
544
}
554
545
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
+
555
551
/*
556
552
* We can have multiple PLIC instances so setup cpuhp state
557
553
* and register syscore operations only once after context
@@ -578,19 +574,6 @@ static int plic_probe(struct platform_device *pdev)
578
574
dev_info (dev , "mapped %d interrupts with %d handlers for %d contexts.\n" ,
579
575
nr_irqs , nr_handlers , nr_contexts );
580
576
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 ;
594
577
}
595
578
596
579
static struct platform_driver plic_driver = {
0 commit comments