]> git.ipfire.org Git - people/arne_f/kernel.git/commitdiff
clk: sunxi-ng: Check kzalloc() for errors and cleanup error path
authorStephen Boyd <sboyd@codeaurora.org>
Sat, 7 Oct 2017 22:36:52 +0000 (22:36 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 8 Nov 2017 09:08:35 +0000 (10:08 +0100)
[ Upstream commit 5d806f9fc8e63d7a44e0fd1ef26a7c27efae0e51 ]

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>
Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/clk/sunxi-ng/ccu_common.c

index 51d4bac97ab301f9d0213ff40327325622fd2109..01d0594c9716be8659b9585cce422ef954a2292d 100644 (file)
@@ -70,6 +70,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;
@@ -85,6 +90,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;
 }