Skip to contentSkip to conversation

clocksource: Freescale: handle of_iomap failures in legacy timer driver

PATCH In review Arvind Yadav 2 participants 3 messages Aug 30, 2016 – Sep 8, 2016 Clocksource, clockevent drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clocksource: Freescale: handle of_iomap failures in legacy timer driver

Check return value of of_iomap and handle errors correctly.

---
 drivers/clocksource/fsl_ftm_timer.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/clocksource/fsl_ftm_timer.c +10 -6
index 738515b..c42d159 100644
@@ -335,36 +335,40 @@ static int __init ftm_timer_init(struct device_node *np)
 	priv->clksrc_base = of_iomap(np, 1);
 	if (!priv->clksrc_base) {
 		pr_err("ftm: unable to map source timer registers\n");
-		goto err;
+		goto err1;
 	}
 
 	ret = -EINVAL;
 	irq = irq_of_parse_and_map(np, 0);
 	if (irq <= 0) {
 		pr_err("ftm: unable to get IRQ from DT, %d\n", irq);
-		goto err;
+		goto err2;
 	}
 
 	priv->big_endian = of_property_read_bool(np, "big-endian");
 
 	freq = ftm_clk_init(np);
 	if (!freq)
-		goto err;
+		goto err2;
 
 	ret = ftm_calc_closest_round_cyc(freq);
 	if (ret)
-		goto err;
+		goto err2;
 
 	ret = ftm_clocksource_init(freq);
 	if (ret)
-		goto err;
+		goto err2;
 
 	ret = ftm_clockevent_init(freq, irq);
 	if (ret)
-		goto err;
+		goto err2;
 
 	return 0;
 
+err2:
+	iounmap(priv->clksrc_base);
+err1:
+	iounmap(priv->clkevt_base);
 err:
 	kfree(priv);
 	return ret;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 4 lines · Arvind Yadav

Check return value of of_iomap and handle errors correctly.

---

Hi Arvind,

usually the undo labels are named like this:

err_unmap_clksrc:

err_unmap_clkevt:

Thanks.

-- Daniel

Quoted 55 lines
 drivers/clocksource/fsl_ftm_timer.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/clocksource/fsl_ftm_timer.c +10 -6
index 738515b..c42d159 100644
@@ -335,36 +335,40 @@ static int __init ftm_timer_init(struct device_node *np)
 	priv->clksrc_base = of_iomap(np, 1);
 	if (!priv->clksrc_base) {
 		pr_err("ftm: unable to map source timer registers\n");
-		goto err;
+		goto err1;
 	}
 
 	ret = -EINVAL;
 	irq = irq_of_parse_and_map(np, 0);
 	if (irq <= 0) {
 		pr_err("ftm: unable to get IRQ from DT, %d\n", irq);
-		goto err;
+		goto err2;
 	}
 
 	priv->big_endian = of_property_read_bool(np, "big-endian");
 
 	freq = ftm_clk_init(np);
 	if (!freq)
-		goto err;
+		goto err2;
 
 	ret = ftm_calc_closest_round_cyc(freq);
 	if (ret)
-		goto err;
+		goto err2;
 
 	ret = ftm_clocksource_init(freq);
 	if (ret)
-		goto err;
+		goto err2;
 
 	ret = ftm_clockevent_init(freq, irq);
 	if (ret)
-		goto err;
+		goto err2;
 
 	return 0;
 
+err2:
+	iounmap(priv->clksrc_base);
+err1:
+	iounmap(priv->clkevt_base);
 err:
 	kfree(priv);
 	return ret;
Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#2 lore raw

Thanks Daniel, I have done the changes as per your suggestion.

Please review it.

-Arvind

Quoted 74 lines · Daniel Lezcano
Quoted 4 lines · Arvind Yadav

Check return value of of_iomap and handle errors correctly.

---

Hi Arvind,

usually the undo labels are named like this:

err_unmap_clksrc:

err_unmap_clkevt:

Thanks.

-- Daniel

Quoted 55 lines
  drivers/clocksource/fsl_ftm_timer.c | 16 ++++++++++------
  1 file changed, 10 insertions(+), 6 deletions(-)
drivers/clocksource/fsl_ftm_timer.c +10 -6
index 738515b..c42d159 100644
@@ -335,36 +335,40 @@ static int __init ftm_timer_init(struct device_node *np)
  	priv->clksrc_base = of_iomap(np, 1);
  	if (!priv->clksrc_base) {
  		pr_err("ftm: unable to map source timer registers\n");
-		goto err;
+		goto err1;
  	}
 
  	ret = -EINVAL;
  	irq = irq_of_parse_and_map(np, 0);
  	if (irq <= 0) {
  		pr_err("ftm: unable to get IRQ from DT, %d\n", irq);
-		goto err;
+		goto err2;
  	}
 
  	priv->big_endian = of_property_read_bool(np, "big-endian");
 
  	freq = ftm_clk_init(np);
  	if (!freq)
-		goto err;
+		goto err2;
 
  	ret = ftm_calc_closest_round_cyc(freq);
  	if (ret)
-		goto err;
+		goto err2;
 
  	ret = ftm_clocksource_init(freq);
  	if (ret)
-		goto err;
+		goto err2;
 
  	ret = ftm_clockevent_init(freq, irq);
  	if (ret)
-		goto err;
+		goto err2;
 
  	return 0;
 
+err2:
+	iounmap(priv->clksrc_base);
+err1:
+	iounmap(priv->clkevt_base);
  err:
  	kfree(priv);
  	return ret;