From patchwork Wed Sep 14 20:03:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 9332365 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 40F4D607FD for ; Wed, 14 Sep 2016 20:03:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F4482A239 for ; Wed, 14 Sep 2016 20:03:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 204152A25F; Wed, 14 Sep 2016 20:03:10 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 A2B342A239 for ; Wed, 14 Sep 2016 20:03:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756232AbcINUDJ (ORCPT ); Wed, 14 Sep 2016 16:03:09 -0400 Received: from mout.web.de ([217.72.192.78]:64320 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754369AbcINUDH (ORCPT ); Wed, 14 Sep 2016 16:03:07 -0400 Received: from [192.168.1.3] ([78.48.193.118]) by smtp.web.de (mrweb101) with ESMTPSA (Nemesis) id 0Lvjiy-1awfP90Nhs-017UY2; Wed, 14 Sep 2016 22:03:03 +0200 Subject: [PATCH 3/4] clk/Renesas-MSTP: Less function calls in cpg_mstp_clocks_init() after error detection To: linux-clk@vger.kernel.org, Geert Uytterhoeven , Laurent Pinchart , Michael Turquette , Simon Horman , Stephen Boyd , Ulf Hansson References: <566ABCD9.1060404@users.sourceforge.net> <1575ddf1-bd1a-fe98-046a-a586eb30fe47@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org, Julia Lawall From: SF Markus Elfring Message-ID: Date: Wed, 14 Sep 2016 22:03:02 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <1575ddf1-bd1a-fe98-046a-a586eb30fe47@users.sourceforge.net> X-Provags-ID: V03:K0:3+6Pa0KPQQQ9nVbavLgUP6uQN4uCWllatnx8pJkmAJDEn6tMkD9 1oCZrNym8yi++25gHfajh3f8xTptKTfBp18vXlRmEdN1cV+nvVQFuulXUnDSlYwNHlJn7ta tDk/cs0tdXY3m9oDw90sPa8kgBT9TbNiJLaOU87NHjXuQT4cuY7++Z1UMTHOPwDdzZwR8P8 52HfPteuVS0kdXaIfidDA== X-UI-Out-Filterresults: notjunk:1; V01:K0:WZe9IPiYYBk=:XIvzESg+GTrc73EU6x6fH5 c0feRfpQJorcFD2udD6lyZ4G7IZFEBGLIVPBZBgCxSaeNC9BgdeDiRYy+IUtSTbsaAuIp+JMz Q3RK9edCXXlWmbh0FUbFcL83nuH6LolPfvjriwyGskz+m74FhZmze2fVdq4LUlUmoZkyvrS9T Te0/+/xnJMRpPVqMSZCC1tEl6s0zMMGFL4gFycQithcdl8lSpmPHbW2h3PSBoSn8uHByyNbUM 5P982aATshQrPSI69TLncvAYq3+XAJiUDlPcUmN19N0my4AQTBO7M22jz7ruM9ccde4EkWzFI 5q9JQd/0HEk+8cxIMDubgVzcrMGuQq1+wY8X8HadLRJM5jLc0aDB0X/oS+P2eTOyqXtl+ZNbj SJEtqB/Oq9ZQcgvrjiMMlK9p8iIvhRPSwFNJPbk6SeacgQh+5fSvFSg49xpqsYks+Pu61OrPn /9rFQdv9ZP4gmct/Z0QGAFBMqN0hwNac2Eb/jtNGSHjt1XWyWj5aaUqANHjdYcbE2jaDFPdxz 2+GCM/AETPTE9cY8SM7hJs250cM9QL5pzy3gJV9TcD66hv/ry/RnQAWdoivLWVCHJBKWbelES fu6FA0QeXVxmB00OLTj4/OC3SmbauMfrcSoO8sNsknY5DD8AXfVy4J7tb+xXDbo+lQvA+5xUm N2+j2tKyyK4ICqPMPUh+Rp39gGzaDb1+NcsNWX//88vtwwh7uADtgxwxbEjM8B7vDXCt1XCBE JbRc4AP8Xx6kK9XTpjvW0VknE9IlLBoEUv+2miazf05sM/jYYJj9t+FjRT/drIO2YVqFT943E AOGi6sc 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 From: Markus Elfring Date: Wed, 14 Sep 2016 21:30:27 +0200 The kfree() function was called in up to two cases by the cpg_mstp_clocks_init() function during error handling even if the passed variable contained a null pointer. * Split a condition check for memory allocation failures so that each pointer from these function calls will be checked immediately. See also background information: Topic "CWE-754: Improper check for unusual or exceptional conditions" Link: https://cwe.mitre.org/data/definitions/754.html * Return directly after a call of the function "kzalloc" failed at the beginning. Signed-off-by: Markus Elfring --- drivers/clk/renesas/clk-mstp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/clk/renesas/clk-mstp.c b/drivers/clk/renesas/clk-mstp.c index 1fdc44b..6c82e0e 100644 --- a/drivers/clk/renesas/clk-mstp.c +++ b/drivers/clk/renesas/clk-mstp.c @@ -167,10 +167,12 @@ static void __init cpg_mstp_clocks_init(struct device_node *np) unsigned int i; group = kzalloc(sizeof(*group), GFP_KERNEL); + if (!group) + return; + clks = kmalloc_array(MSTP_MAX_CLOCKS, sizeof(*clks), GFP_KERNEL); - if (group == NULL || clks == NULL) { + if (!clks) { kfree(group); - kfree(clks); return; }