Re: [PATCH v5 03/14] irqchip/csky-mpintc: Fix potential resource leaks

2020-07-06 Thread Markus Elfring
> … Thus add jump targets for the completion of the desired
> exception handling. By the way, do some coding-style cleanups
> suggested by Markus.

I propose to split these changes.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id=dcb7fd82c75ee2d6e6f9d8cc71c52519ed52e258#n138

Would you like to support easier back-porting of a fix
besides another bit of possible source code beautification?


…
+++ b/drivers/irqchip/irq-csky-mpintc.c
@@ -241,14 +241,16 @@ csky_mpintc_init(struct device_node *node, struct 
device_node *parent)
…
INTCG_base = ioremap(mfcr("cr<31, 14>"),
-INTCL_SIZE*nr_cpu_ids + INTCG_SIZE);
…
+INTCL_SIZE * nr_cpu_ids + INTCG_SIZE);

Can any macro (or function) be helpful for such a size computation?

Regards,
Markus


[PATCH v5 03/14] irqchip/csky-mpintc: Fix potential resource leaks

2020-07-05 Thread Tiezhu Yang
In the function csky_mpintc_init(), system resources "__trigger",
"INTCG_base" and "root_domain" were not released in a few error
cases. Thus add jump targets for the completion of the desired
exception handling. By the way, do some coding-style cleanups
suggested by Markus.

Fixes: d8a5f5f79122 ("irqchip: add C-SKY SMP interrupt controller")
Signed-off-by: Tiezhu Yang 
---
 drivers/irqchip/irq-csky-mpintc.c | 31 ++-
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/drivers/irqchip/irq-csky-mpintc.c 
b/drivers/irqchip/irq-csky-mpintc.c
index a1534ed..df41735 100644
--- a/drivers/irqchip/irq-csky-mpintc.c
+++ b/drivers/irqchip/irq-csky-mpintc.c
@@ -241,14 +241,16 @@ csky_mpintc_init(struct device_node *node, struct 
device_node *parent)
nr_irq = INTC_IRQS;
 
__trigger  = kcalloc(nr_irq, sizeof(unsigned long), GFP_KERNEL);
-   if (__trigger == NULL)
+   if (!__trigger)
return -ENXIO;
 
-   if (INTCG_base == NULL) {
+   if (!INTCG_base) {
INTCG_base = ioremap(mfcr("cr<31, 14>"),
-INTCL_SIZE*nr_cpu_ids + INTCG_SIZE);
-   if (INTCG_base == NULL)
-   return -EIO;
+INTCL_SIZE * nr_cpu_ids + INTCG_SIZE);
+   if (!INTCG_base) {
+   ret = -EIO;
+   goto err_free;
+   }
 
INTCL_base = INTCG_base + INTCG_SIZE;
 
@@ -257,8 +259,10 @@ csky_mpintc_init(struct device_node *node, struct 
device_node *parent)
 
root_domain = irq_domain_add_linear(node, nr_irq, _irqdomain_ops,
NULL);
-   if (!root_domain)
-   return -ENXIO;
+   if (!root_domain) {
+   ret = -ENXIO;
+   goto err_iounmap;
+   }
 
/* for every cpu */
for_each_present_cpu(cpu) {
@@ -270,12 +274,21 @@ csky_mpintc_init(struct device_node *node, struct 
device_node *parent)
 
 #ifdef CONFIG_SMP
ipi_irq = irq_create_mapping(root_domain, IPI_IRQ);
-   if (!ipi_irq)
-   return -EIO;
+   if (!ipi_irq) {
+   irq_domain_remove(root_domain);
+   ret = -EIO;
+   goto err_iounmap;
+   }
 
set_send_ipi(_mpintc_send_ipi, ipi_irq);
 #endif
 
return 0;
+
+err_iounmap:
+   iounmap(INTCG_base);
+err_free:
+   kfree(__trigger);
+   return ret;
 }
 IRQCHIP_DECLARE(csky_mpintc, "csky,mpintc", csky_mpintc_init);
-- 
2.1.0