Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1573512 > unrolled thread

[PATCH] clk: sunxi-ng: Check kzalloc() for errors and cleanup error path

Started byStephen Boyd <sboyd@codeaurora.org>
First post2017-02-04 00:10 +0100
Last post2017-02-06 23:50 +0100
Articles 3 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] clk: sunxi-ng: Check kzalloc() for errors and cleanup error path Stephen Boyd <sboyd@codeaurora.org> - 2017-02-04 00:10 +0100
    Re: [PATCH] clk: sunxi-ng: Check kzalloc() for errors and cleanup  error path Maxime Ripard <maxime.ripard@free-electrons.com> - 2017-02-06 12:00 +0100
      Re: [PATCH] clk: sunxi-ng: Check kzalloc() for errors and cleanup  error path Stephen Boyd <sboyd@codeaurora.org> - 2017-02-06 23:50 +0100

#1573512 — [PATCH] clk: sunxi-ng: Check kzalloc() for errors and cleanup error path

FromStephen Boyd <sboyd@codeaurora.org>
Date2017-02-04 00:10 +0100
Subject[PATCH] clk: sunxi-ng: Check kzalloc() for errors and cleanup error path
Message-ID<t6V9o-8rI-15@gated-at.bofh.it>
This kzalloc() could fail. Let's bail out with -ENOMEM here
instead of NULL dereferencing. That silences static checkers. We
should also cleanup on the error path even though this function
returning an error probably means the system won't boot.

Cc: Chen-Yu Tsai <wens@csie.org>
Cc: Maxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
---

The code looks suspiciously like the error handling was removed
on purpose.

 drivers/clk/sunxi-ng/ccu_common.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/clk/sunxi-ng/ccu_common.c b/drivers/clk/sunxi-ng/ccu_common.c
index 6986e11e91b0..8a47bafd7890 100644
--- a/drivers/clk/sunxi-ng/ccu_common.c
+++ b/drivers/clk/sunxi-ng/ccu_common.c
@@ -75,6 +75,11 @@ int sunxi_ccu_probe(struct device_node *node, void __iomem *reg,
 		goto err_clk_unreg;
 
 	reset = kzalloc(sizeof(*reset), GFP_KERNEL);
+	if (!reset) {
+		ret = -ENOMEM;
+		goto err_alloc_reset;
+	}
+
 	reset->rcdev.of_node = node;
 	reset->rcdev.ops = &ccu_reset_ops;
 	reset->rcdev.owner = THIS_MODULE;
@@ -90,6 +95,16 @@ int sunxi_ccu_probe(struct device_node *node, void __iomem *reg,
 	return 0;
 
 err_of_clk_unreg:
+	kfree(reset);
+err_alloc_reset:
+	of_clk_del_provider(node);
 err_clk_unreg:
+	while (--i >= 0) {
+		struct clk_hw *hw = desc->hw_clks->hws[i];
+
+		if (!hw)
+			continue;
+		clk_hw_unregister(hw);
+	}
 	return ret;
 }
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

[toc] | [next] | [standalone]


#1574554 — Re: [PATCH] clk: sunxi-ng: Check kzalloc() for errors and cleanup error path

FromMaxime Ripard <maxime.ripard@free-electrons.com>
Date2017-02-06 12:00 +0100
SubjectRe: [PATCH] clk: sunxi-ng: Check kzalloc() for errors and cleanup error path
Message-ID<t7PbA-3SX-5@gated-at.bofh.it>
In reply to#1573512

[Multipart message — attachments visible in raw view] — view raw

On Fri, Feb 03, 2017 at 03:00:50PM -0800, Stephen Boyd wrote:
> This kzalloc() could fail. Let's bail out with -ENOMEM here
> instead of NULL dereferencing. That silences static checkers. We
> should also cleanup on the error path even though this function
> returning an error probably means the system won't boot.
> 
> Cc: Chen-Yu Tsai <wens@csie.org>
> Cc: Maxime Ripard <maxime.ripard@free-electrons.com>
> Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>

Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Can you apply it directly?

Thanks,
Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

[toc] | [prev] | [next] | [standalone]


#1575216 — Re: [PATCH] clk: sunxi-ng: Check kzalloc() for errors and cleanup error path

FromStephen Boyd <sboyd@codeaurora.org>
Date2017-02-06 23:50 +0100
SubjectRe: [PATCH] clk: sunxi-ng: Check kzalloc() for errors and cleanup error path
Message-ID<t80gG-2FR-9@gated-at.bofh.it>
In reply to#1574554
On 02/06, Maxime Ripard wrote:
> On Fri, Feb 03, 2017 at 03:00:50PM -0800, Stephen Boyd wrote:
> > This kzalloc() could fail. Let's bail out with -ENOMEM here
> > instead of NULL dereferencing. That silences static checkers. We
> > should also cleanup on the error path even though this function
> > returning an error probably means the system won't boot.
> > 
> > Cc: Chen-Yu Tsai <wens@csie.org>
> > Cc: Maxime Ripard <maxime.ripard@free-electrons.com>
> > Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
> 
> Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>
> 
> Can you apply it directly?
> 

Yep. Thanks.

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web