Skip to contentSkip to conversation

clocksource/timer-imx-gpt: Preventing resource leakage in error case.

PATCH In review Arvind Yadav 2 participants 3 messages Sep 23, 2016 – Sep 24, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 clocksource/timer-imx-gpt: Preventing resource leakage in error case.

-Free previously allocated memory.
-Unmap I/O memory from kernel address space.

---
 drivers/clocksource/timer-imx-gpt.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)
drivers/clocksource/timer-imx-gpt.c +17 -6
index f595460..31cfccf 100644
@@ -489,12 +489,16 @@ static int __init mxc_timer_init_dt(struct device_node *np,  enum imx_gpt_type t
 		return -ENOMEM;
 
 	imxtm->base = of_iomap(np, 0);
-	if (!imxtm->base)
-		return -ENXIO;
+	if (!imxtm->base) {
+		ret = -ENXIO;
+		goto error_free;
+	}
 
 	imxtm->irq = irq_of_parse_and_map(np, 0);
-	if (imxtm->irq <= 0)
-		return -EINVAL;
+	if (imxtm->irq <= 0) {
+		ret = -EINVAL;
+		goto error_iounmap;
+	}
 
 	imxtm->clk_ipg = of_clk_get_by_name(np, "ipg");
 
@@ -506,12 +510,19 @@ static int __init mxc_timer_init_dt(struct device_node *np,  enum imx_gpt_type t
 	imxtm->type = type;
 
 	ret = _mxc_timer_init(imxtm);
-	if (ret)
-		return ret;
+	if (ret) {
+		goto error_iounmap;
+	}
 
 	initialized = 1;
 
 	return 0;
+
+error_iounmap:
+	iounmap(imxtm->base);
+error_kfree:
+	kfree(imxtm);
+	return ret;
 }
 
 static int __init imx1_timer_init_dt(struct device_node *np)
Signature · 1 line
2.7.4
#1 lore raw

On Fri, 23 Sep 2016, Arvind Yadav wrote:

So last time (V2) you had a almost perfect subject line:

clocksrouce/timer-imz-gpt: Prevent resource leaks in error path

The only issue was the clocksrcouce typo. Now you made it:

clocksource/timer-imx-gpt: Preventing resource leakage in error case.

Documentation/SubmittingPatches says:

Describe your changes in imperative mood ... as if you are giving orders to the codebase to change its behaviour.

"Preventing" is not imperative and the above is not a proper sentence, while the V2 one is.

drivers/clocksource/timer-imx-gpt.c static int __init mxc_timer_init_dt(struct device_node *np, enum imx_gpt_type t · line 515

Quoted 6 lines
drivers/clocksource/timer-imx-gpt.c +3 -2
 	ret = _mxc_timer_init(imxtm);
-	if (ret)
-		return ret;
+	if (ret) {
+		goto error_iounmap;
+	}

Further Documentation/SubmittingPatches also tells you which tools to use _before_ submission. If you'd used them then the above change would look different. You surely can figure that out yourself.

Thanks,

tglx

#2 lore raw

Thanks for help and suggestion.
I am looking 'Documentation/SubmittingPatches'.

Thanks
-Arvind Yadav

Quoted 33 lines · Thomas Gleixner

On Fri, 23 Sep 2016, Arvind Yadav wrote:

So last time (V2) you had a almost perfect subject line:

clocksrouce/timer-imz-gpt: Prevent resource leaks in error path

The only issue was the clocksrcouce typo. Now you made it:

clocksource/timer-imx-gpt: Preventing resource leakage in error case.

Documentation/SubmittingPatches says:

Describe your changes in imperative mood ... as if you are giving orders to the codebase to change its behaviour.

"Preventing" is not imperative and the above is not a proper sentence, while the V2 one is.

drivers/clocksource/timer-imx-gpt.c static int __init mxc_timer_init_dt(struct device_node *np, enum imx_gpt_type t · line 515

Quoted 6 lines
  	ret = _mxc_timer_init(imxtm);
drivers/clocksource/timer-imx-gpt.c +3 -2
-	if (ret)
-		return ret;
+	if (ret) {
+		goto error_iounmap;
+	}

Further Documentation/SubmittingPatches also tells you which tools to use _before_ submission. If you'd used them then the above change would look different. You surely can figure that out yourself.

Thanks,

tglx