Return-Path: Received: from omzsmtpe02.verizonbusiness.com ([199.249.25.209]:22618 "EHLO omzsmtpe02.verizonbusiness.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752812AbdJGWhr (ORCPT ); Sat, 7 Oct 2017 18:37:47 -0400 From: "Levin, Alexander (Sasha Levin)" Cc: Stephen Boyd , Chen-Yu Tsai , "Levin, Alexander (Sasha Levin)" To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" Subject: [PATCH review for 4.9 26/50] clk: sunxi-ng: Check kzalloc() for errors and cleanup error path Date: Sat, 7 Oct 2017 22:36:52 +0000 Message-ID: <20171007223636.24797-26-alexander.levin@verizon.com> References: <20171007223636.24797-1-alexander.levin@verizon.com> In-Reply-To: <20171007223636.24797-1-alexander.levin@verizon.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Stephen Boyd [ 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 Acked-by: Maxime Ripard Signed-off-by: Stephen Boyd Signed-off-by: Sasha Levin --- 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_c= ommon.c index 51d4bac97ab3..01d0594c9716 100644 --- a/drivers/clk/sunxi-ng/ccu_common.c +++ b/drivers/clk/sunxi-ng/ccu_common.c @@ -70,6 +70,11 @@ int sunxi_ccu_probe(struct device_node *node, void __iom= em *reg, goto err_clk_unreg; =20 reset =3D kzalloc(sizeof(*reset), GFP_KERNEL); + if (!reset) { + ret =3D -ENOMEM; + goto err_alloc_reset; + } + reset->rcdev.of_node =3D node; reset->rcdev.ops =3D &ccu_reset_ops; reset->rcdev.owner =3D THIS_MODULE; @@ -85,6 +90,16 @@ int sunxi_ccu_probe(struct device_node *node, void __iom= em *reg, return 0; =20 err_of_clk_unreg: + kfree(reset); +err_alloc_reset: + of_clk_del_provider(node); err_clk_unreg: + while (--i >=3D 0) { + struct clk_hw *hw =3D desc->hw_clks->hws[i]; + + if (!hw) + continue; + clk_hw_unregister(hw); + } return ret; } --=20 2.11.0