From patchwork Wed Jan 11 13:40:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 9510081 X-Patchwork-Delegate: sboyd@codeaurora.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 07E81601E7 for ; Wed, 11 Jan 2017 13:41:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA957284AD for ; Wed, 11 Jan 2017 13:41:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF26F28634; Wed, 11 Jan 2017 13:41:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9746284AD for ; Wed, 11 Jan 2017 13:41:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S937844AbdAKNlu (ORCPT ); Wed, 11 Jan 2017 08:41:50 -0500 Received: from mout.kundenserver.de ([212.227.126.135]:63551 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S937381AbdAKNlt (ORCPT ); Wed, 11 Jan 2017 08:41:49 -0500 Received: from wuerfel.lan ([78.43.21.235]) by mrelayeu.kundenserver.de (mreue003 [212.227.15.129]) with ESMTPA (Nemesis) id 0MaX6b-1cCGAo0Fnl-00KAdL; Wed, 11 Jan 2017 14:41:11 +0100 From: Arnd Bergmann To: Michael Turquette , Stephen Boyd Cc: Arnd Bergmann , Maxime Coquelin , Alexandre Torgue , Gabriel Fernandez , Rob Herring , Christophe JAILLET , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] clk: stm32f4: avoid uninitialized variable access Date: Wed, 11 Jan 2017 14:40:52 +0100 Message-Id: <20170111134107.3821564-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:SfFlVpKsRZUGQbd/ZVVI4iopf86sQByf1HJxGxmVZMV16PGYC9M Le/r1gNVWWH3P5fx7hst9gNgI49c9UQZMOuKEQKTucpi2Ke86nxqa/19dyfQeUpPt57ijie NHLagRRIXf/JYQQwh1QpVdYTAVdNZbicSmpjQC3K1Y6a+uGvfhPby8+r+5q/Ul9kWa2xTI4 z0+R/APjBOIhABrJ8VOEw== X-UI-Out-Filterresults: notjunk:1; V01:K0:Y2C7pgs9AQs=:+QSK+gR7fNYpi0K6tfdUCk MAp9AxIV4di+Uv28ARNijjaTfn9Xv+hR8x2ELWE3wKE4uDmVPMuzY8212eYaGr3kM/mIM90jg DUCXhS93Ap8uhuNHaFtWExK/4G9vLJWywZ3NT+kCIrvvKLNGLjpikIDFhvgMmB4OhbEH4hBWa zxsK3l/Gkk3kbSVQsBYFLw7hP2c3KTMZsILlg+PlcjVgCPo3GwkgDbDPaZwP2xwpyU92Q+cEv Zb5erglP/AwBN1Cigb3aEpDCcBcBf5czSAFcxYcWqrOodM5QNBC3hmE8Yh6ZbIXo2gx/oSYQT XgxJcWBTRUxfD+Bz+CDaINdeagFx0ADcbVuqY7ZPbvq/djnOR3Q3Kd6XJ+oEqYK2WoehxJjQO TaxmfYjmsWqIaqgtBY+difOJXitrRwpJhR7BZ8GZ5vpLT8ABnupHjEF51DlwlPih9BCUT9iF5 jfkLaHuAy7WhDaJxrJ0D0gRyVCLdo2XEwqLHjpUhPa+IYDCwwoFGRGpXM+Imp5W4rQ9Thst7B qYLQ0Qm4vniHikZO/q+tS4ITm/JuTDqL7AUSaXMiLQZq3eIdMZ0oCoBVVYoP4fU+fmTK9eki0 +rMU4bsQ5Kq9Ik7W/1p1x+mSIbE2QBVP5s994GFjyDPqUh4StpNVRmPXIv+8Wiu7Ova8peJB7 umzTfGeHRzd2OXp9jo1TUR4CmCP+1tVrUZZX1QW60bQ2lSETh4ldYTLKg3mfoR8xlu2I= Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The failure path in the newly added function tries to free an uninitialized pointer: drivers/clk/clk-stm32f4.c: In function 'stm32f4_rcc_init': drivers/clk/clk-stm32f4.c:1106:4: error: 'gate' may be used uninitialized in this function [-Werror=maybe-uninitialized] I'm adding an initialization to NULL here to make the kfree() succeed, and I'm also rearranging the cleanup so that the same kfree() is used for any error path, making the function slightly more robust against newly introduced bugs in the error handling. Fixes: daf2d117cbca ("clk: stm32f4: Add lcd-tft clock") Signed-off-by: Arnd Bergmann Acked-by: Gabriel Fernandez --- drivers/clk/clk-stm32f4.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/clk/clk-stm32f4.c b/drivers/clk/clk-stm32f4.c index 42f8534996de..4a3bb6e63525 100644 --- a/drivers/clk/clk-stm32f4.c +++ b/drivers/clk/clk-stm32f4.c @@ -1080,7 +1080,7 @@ static struct clk_hw *stm32_register_aux_clk(const char *name, unsigned long flags, spinlock_t *lock) { struct clk_hw *hw; - struct clk_gate *gate; + struct clk_gate *gate = NULL; struct clk_mux *mux = NULL; struct clk_hw *mux_hw = NULL, *gate_hw = NULL; const struct clk_ops *mux_ops = NULL, *gate_ops = NULL; @@ -1103,7 +1103,6 @@ static struct clk_hw *stm32_register_aux_clk(const char *name, if (offset_mux != NO_MUX) { mux = kzalloc(sizeof(*mux), GFP_KERNEL); if (!mux) { - kfree(gate); hw = ERR_PTR(-EINVAL); goto fail; } @@ -1116,8 +1115,10 @@ static struct clk_hw *stm32_register_aux_clk(const char *name, mux_ops = &clk_mux_ops; } - if (mux_hw == NULL && gate_hw == NULL) - return ERR_PTR(-EINVAL); + if (mux_hw == NULL && gate_hw == NULL) { + hw = ERR_PTR(-EINVAL); + goto fail; + } hw = clk_hw_register_composite(NULL, name, parent_names, num_parents, mux_hw, mux_ops, @@ -1125,11 +1126,12 @@ static struct clk_hw *stm32_register_aux_clk(const char *name, gate_hw, gate_ops, flags); +fail: if (IS_ERR(hw)) { kfree(gate); kfree(mux); } -fail: + return hw; }