Skip to contentSkip to conversation

soc: sifive: ccache: fix missing iounmap() in error path in sifive_ccache_init()

PATCH Superseded Yang Yingliang 2 participants 5 messages Oct 17, 2022 – Oct 18, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 soc: sifive: ccache: fix missing iounmap() in error path in sifive_ccache_init()

Add missing iounmap() before return error from sifive_ccache_init().

Fixes a967a289f169 ("RISC-V: sifive_l2_cache: Add L2 cache controller driver for SiFive SoCs")
---
 drivers/soc/sifive/sifive_ccache.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/soc/sifive/sifive_ccache.c +11 -4
index 1c171150e878..25019c16d8ae 100644
@@ -222,13 +222,16 @@ static int __init sifive_ccache_init(void)
 	if (!ccache_base)
 		return -ENOMEM;
 
-	if (of_property_read_u32(np, "cache-level", &level))
-		return -ENOENT;
+	if (of_property_read_u32(np, "cache-level", &level)) {
+		rc = -ENOENT;
+		goto err_unmap;
+	}
 
 	intr_num = of_property_count_u32_elems(np, "interrupts");
 	if (!intr_num) {
 		pr_err("No interrupts property\n");
-		return -ENODEV;
+		rc = -ENODEV;
+		goto err_unmap;
 	}
 
 	for (i = 0; i < intr_num; i++) {
@@ -237,7 +240,7 @@ static int __init sifive_ccache_init(void)
 				 NULL);
 		if (rc) {
 			pr_err("Could not request IRQ %d\n", g_irq[i]);
-			return rc;
+			goto err_unmap;
 		}
 	}
 
@@ -250,6 +253,10 @@ static int __init sifive_ccache_init(void)
 	setup_sifive_debug();
 #endif
 	return 0;
+
+err_unmap:
+	iounmap(ccache_base);
+	return rc;
 }
 
 device_initcall(sifive_ccache_init);
Signature · 7 lines
2.25.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#1 lore raw

PATCH 2/2 soc: sifive: ccache: fix missing free_irq() in error path in sifive_ccache_init()

Add missing free_irq() before return error from sifive_ccache_init().

Fixes a967a289f169 ("RISC-V: sifive_l2_cache: Add L2 cache controller driver for SiFive SoCs")
---
 drivers/soc/sifive/sifive_ccache.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/soc/sifive/sifive_ccache.c +4 -1
index 25019c16d8ae..98269d056728 100644
@@ -240,7 +240,7 @@ static int __init sifive_ccache_init(void)
 				 NULL);
 		if (rc) {
 			pr_err("Could not request IRQ %d\n", g_irq[i]);
-			goto err_unmap;
+			goto err_free_irq;
 		}
 	}
 
@@ -254,6 +254,9 @@ static int __init sifive_ccache_init(void)
 #endif
 	return 0;
 
+err_free_irq:
+	while (--i >= 0)
+		free_irq(g_irq[i], NULL);
 err_unmap:
 	iounmap(ccache_base);
 	return rc;
Signature · 7 lines
2.25.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] soc: sifive: ccache: fix missing free_irq() in error path in sifive_ccache_init()

Quoted 39 lines · Yang Yingliang

Add missing free_irq() before return error from sifive_ccache_init().

Fixes a967a289f169 ("RISC-V: sifive_l2_cache: Add L2 cache controller driver for SiFive SoCs")
---
 drivers/soc/sifive/sifive_ccache.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/soc/sifive/sifive_ccache.c +4 -1
index 25019c16d8ae..98269d056728 100644
@@ -240,7 +240,7 @@ static int __init sifive_ccache_init(void)
 				 NULL);
 		if (rc) {
 			pr_err("Could not request IRQ %d\n", g_irq[i]);
-			goto err_unmap;
+			goto err_free_irq;
 		}
 	}
 
@@ -254,6 +254,9 @@ static int __init sifive_ccache_init(void)
 #endif
 	return 0;
 
+err_free_irq:
+	while (--i >= 0)
+		free_irq(g_irq[i], NULL);
 err_unmap:
 	iounmap(ccache_base);
 	return rc;
Signature · 7 lines
2.25.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Reviewed-by on v1 1/2
#3 lore raw
In reply to Yang Yingliang
Quoted 3 lines · Yang Yingliang

Add missing iounmap() before return error from sifive_ccache_init().

Fixes a967a289f169 ("RISC-V: sifive_l2_cache: Add L2 cache controller driver for SiFive SoCs")

Hey Yang Yangliang,

Both of these patches look good to me.

One question - of_find_matching_node() increments the refcount of np right? It seems to me like we need an of_node_put() here, at the very least in the error paths (do we need it in the success path too?). If we are going to add cleanup to this driver, we may as well go the whole hog I think.

In terms of the success paths, I assume the first place we can safely let the reference go is just before the call to ccache_config_read()?

Please lmk if I am misunderstanding anything here... Thanks,
Conor.

Quoted 57 lines
---
 drivers/soc/sifive/sifive_ccache.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/soc/sifive/sifive_ccache.c +11 -4
index 1c171150e878..25019c16d8ae 100644
@@ -222,13 +222,16 @@ static int __init sifive_ccache_init(void)
 	if (!ccache_base)
 		return -ENOMEM;
 
-	if (of_property_read_u32(np, "cache-level", &level))
-		return -ENOENT;
+	if (of_property_read_u32(np, "cache-level", &level)) {
+		rc = -ENOENT;
+		goto err_unmap;
+	}
 
 	intr_num = of_property_count_u32_elems(np, "interrupts");
 	if (!intr_num) {
 		pr_err("No interrupts property\n");
-		return -ENODEV;
+		rc = -ENODEV;
+		goto err_unmap;
 	}
 
 	for (i = 0; i < intr_num; i++) {
@@ -237,7 +240,7 @@ static int __init sifive_ccache_init(void)
 				 NULL);
 		if (rc) {
 			pr_err("Could not request IRQ %d\n", g_irq[i]);
-			return rc;
+			goto err_unmap;
 		}
 	}
 
@@ -250,6 +253,10 @@ static int __init sifive_ccache_init(void)
 	setup_sifive_debug();
 #endif
 	return 0;
+
+err_unmap:
+	iounmap(ccache_base);
+	return rc;
 }
 
 device_initcall(sifive_ccache_init);
Signature · 7 lines
2.25.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#4 lore raw

Hi Conor,

Quoted 9 lines · Conor Dooley
Quoted 3 lines · Yang Yingliang

Add missing iounmap() before return error from sifive_ccache_init().

Fixes a967a289f169 ("RISC-V: sifive_l2_cache: Add L2 cache controller driver for SiFive SoCs")

Hey Yang Yangliang,

Both of these patches look good to me.

Quoted 8 lines

One question - of_find_matching_node() increments the refcount of np right? It seems to me like we need an of_node_put() here, at the very least in the error paths (do we need it in the success path too?). If we are going to add cleanup to this driver, we may as well go the whole hog I think.

In terms of the success paths, I assume the first place we can safely let the reference go is just before the call to ccache_config_read()?

Thanks for reviewing!

Yes, I think you are right, the refcount of np need be put in error paths, and it's OK to put refcount before ccache_config_read() in normal path. I can send another patch to fix this.

Thanks,
Yang

Quoted 58 lines

Please lmk if I am misunderstanding anything here... Thanks,
Conor.

Quoted 53 lines
---
  drivers/soc/sifive/sifive_ccache.c | 15 +++++++++++----
  1 file changed, 11 insertions(+), 4 deletions(-)
drivers/soc/sifive/sifive_ccache.c +11 -4
index 1c171150e878..25019c16d8ae 100644
@@ -222,13 +222,16 @@ static int __init sifive_ccache_init(void)
  	if (!ccache_base)
  		return -ENOMEM;
 
-	if (of_property_read_u32(np, "cache-level", &level))
-		return -ENOENT;
+	if (of_property_read_u32(np, "cache-level", &level)) {
+		rc = -ENOENT;
+		goto err_unmap;
+	}
 
  	intr_num = of_property_count_u32_elems(np, "interrupts");
  	if (!intr_num) {
  		pr_err("No interrupts property\n");
-		return -ENODEV;
+		rc = -ENODEV;
+		goto err_unmap;
  	}
 
  	for (i = 0; i < intr_num; i++) {
@@ -237,7 +240,7 @@ static int __init sifive_ccache_init(void)
  				 NULL);
  		if (rc) {
  			pr_err("Could not request IRQ %d\n", g_irq[i]);
-			return rc;
+			goto err_unmap;
  		}
  	}
 
@@ -250,6 +253,10 @@ static int __init sifive_ccache_init(void)
  	setup_sifive_debug();
  #endif
  	return 0;
+
+err_unmap:
+	iounmap(ccache_base);
+	return rc;
  }
 
  device_initcall(sifive_ccache_init);
Signature · 1 line
2.25.1
Quoted 5 lines
Quoted 4 lines

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv