From patchwork Fri Feb 3 23:00:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 9555269 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 9AA3260405 for ; Fri, 3 Feb 2017 23:00:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6ED0C27BE5 for ; Fri, 3 Feb 2017 23:00:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 63A1328111; Fri, 3 Feb 2017 23:00:54 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham 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 E9EDD27BE5 for ; Fri, 3 Feb 2017 23:00:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752709AbdBCXAx (ORCPT ); Fri, 3 Feb 2017 18:00:53 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:43782 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752527AbdBCXAw (ORCPT ); Fri, 3 Feb 2017 18:00:52 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id D069060719; Fri, 3 Feb 2017 23:00:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1486162851; bh=pYdwbPkNuoDbS852g6ys1pXsZUC0aMg451aLRrcW8tM=; h=From:To:Cc:Subject:Date:From; b=ZTrvEq8i1wVpBYARwyMwkY6/690nCH1lezHFj3AhlnldwY6GJ/hkwgPtlKNoTnExw 5856WBllb+xF+1CWbnSgMMq7TZ6vygdPkWizCfyGPzeTTImTDseGfbKvxiNZ96Tnt3 C3+/wXum1mtApp4gPj2v6A8SO5Y6vmWugZKQmOmQ= Received: from sboyd-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: sboyd@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 01A8260584; Fri, 3 Feb 2017 23:00:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1486162851; bh=pYdwbPkNuoDbS852g6ys1pXsZUC0aMg451aLRrcW8tM=; h=From:To:Cc:Subject:Date:From; b=ZTrvEq8i1wVpBYARwyMwkY6/690nCH1lezHFj3AhlnldwY6GJ/hkwgPtlKNoTnExw 5856WBllb+xF+1CWbnSgMMq7TZ6vygdPkWizCfyGPzeTTImTDseGfbKvxiNZ96Tnt3 C3+/wXum1mtApp4gPj2v6A8SO5Y6vmWugZKQmOmQ= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 01A8260584 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=sboyd@codeaurora.org From: Stephen Boyd To: Michael Turquette , Stephen Boyd Cc: linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Chen-Yu Tsai , Maxime Ripard Subject: [PATCH] clk: sunxi-ng: Check kzalloc() for errors and cleanup error path Date: Fri, 3 Feb 2017 15:00:50 -0800 Message-Id: <20170203230050.26181-1-sboyd@codeaurora.org> X-Mailer: git-send-email 2.11.0 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 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 Cc: Maxime Ripard Signed-off-by: Stephen Boyd Acked-by: Maxime Ripard --- 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; }