From patchwork Sun Dec 24 16:36:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Elfring X-Patchwork-Id: 183087 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp30088dyb; Sun, 24 Dec 2023 08:37:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IFbjUzYzJ2uPI+lIUqrPiAXUrfTg4utiWUMab9DwixHpQVctwJpci6BF5mhyctndW/OlWAJ X-Received: by 2002:a05:622a:118e:b0:425:8f81:6c95 with SMTP id m14-20020a05622a118e00b004258f816c95mr6516844qtk.12.1703435859986; Sun, 24 Dec 2023 08:37:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703435859; cv=none; d=google.com; s=arc-20160816; b=lwBTt1RzWbcIqRGivfi5VZRSIWAQddM6JgRZ/JprPyVG8bCrzWCZp5LguTFgXPYIEJ TQWC8n7siZMXslLuig2gup2lCMUvOXTckxSYUqU9wbhmIN1Y1IZt+8Q0DGOYujCfiuu3 yXQ2bmDYfspSOIVdkgdczDCv/ZE1YSP6S7JfT960Hj8oLkQ1ObkZ7v9RlxARwPBCAuK3 kmyCORKSiEvOd88xOKiRIrcsOlFvShfzPJalS7M/fU4vorgkKIs3uZ87hEjJ+g+HYWVC tTHNVQpIwutm1eMrHJ72jA+A7uYkN3RVzpNsNnT3enBiuNnTvP8pun+xzsLUB/w5jLGz Qipg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=T9u4solGEcwZXbgSKeafa5rI8oOhRUXkZHPfzeeWl68=; fh=sjHIukpoR7qU1+33gpK0xo2A7Js9I7GnF+G77h/eU8w=; b=0ovNSNEr49nwDIPvtw/gVrjldVaNVqkFo3AaxnRwrJnC4jCREz4zh25q3MLvYKEDjN yw9z/t78Yu/BtEG4bO23V7uIqLy5gxgN1rIgS460cxC89hlkkwzK2Ftnr6VplsEHZSrk i4Zid+A6AFzXemNbP5Bgx5sDXA1QY2h+DPZGPixRZc4b6iPEM7uNv+RE4wt10/IDgCNU bTxLuhZi4N5AyHZnT1wYVmcCydqZxb59VbHXFYjpe92VvWxuqVr9zeVK/wymaSaa5B9e 9cFxFiqxV15unkXHGYweHwrRoMPWWn9u4MNNJGvIkN2jwiqBjftQ3WSQbq3S6qxH4xto rYBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@web.de header.s=s29768273 header.b=d2btJZgB; spf=pass (google.com: domain of linux-kernel+bounces-10760-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10760-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=web.de Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f10-20020ac87f0a000000b00425826ea01bsi9221079qtk.212.2023.12.24.08.37.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Dec 2023 08:37:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10760-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@web.de header.s=s29768273 header.b=d2btJZgB; spf=pass (google.com: domain of linux-kernel+bounces-10760-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10760-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=web.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C48E11C20ABE for ; Sun, 24 Dec 2023 16:37:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 11895D282; Sun, 24 Dec 2023 16:37:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=markus.elfring@web.de header.b="d2btJZgB" X-Original-To: linux-kernel@vger.kernel.org Received: from mout.web.de (mout.web.de [212.227.15.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71608747F; Sun, 24 Dec 2023 16:37:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1703435819; x=1704040619; i=markus.elfring@web.de; bh=HUtTyqgAjeXilij1EZvW9BI8jaGz1KwDa0ackvdaMP0=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References: In-Reply-To; b=d2btJZgBjrL9shctEps3kZP6ar2tniPSbSRCDxu5GQKJuq9gCNGhMqPt2GrvewjQ 3IDdl8d6sMRsR6RugTGpDyuJ8Ny54xfbFq/osyKsFMDoqUGOqMivCT5iVw/Z8zHCR FCBCHvRnPw6aZ8gdXOOdq/roceRzdW8gN0OxeLcSmzHjeVHdzJjWpkmJTlcvrkJM1 MpXaBo0FyGv+8i8VfajSsWx2eCa3MqO94+K6TqEQTinPg0c5MvzpFCSjZwzwGuiIN inQVAyjI0MEE+/MMujKR5HtPxyygugniPGRUwm672dw+rBdOc8rF7ZR+FrPj1pkmA 1wzR9sjG78uxX4Lm9A== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.21] ([94.31.85.95]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1M6HKG-1rJcGY3hhQ-0070lV; Sun, 24 Dec 2023 17:36:58 +0100 Message-ID: <422c6249-31ac-410e-911d-ec25aeee126a@web.de> Date: Sun, 24 Dec 2023 17:36:57 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 01/10] clk: ti: Less function calls in of_omap2_apll_setup() after error detection Content-Language: en-GB From: Markus Elfring To: linux-omap@vger.kernel.org, linux-clk@vger.kernel.org, kernel-janitors@vger.kernel.org, Andy Shevchenko , Claudiu Beznea , Michael Turquette , Rob Herring , Stephen Boyd , Tero Kristo , Tony Lindgren Cc: LKML , cocci@inria.fr References: <20849a8e-e0f5-46df-ad8a-9eae6cbe337b@web.de> In-Reply-To: <20849a8e-e0f5-46df-ad8a-9eae6cbe337b@web.de> X-Provags-ID: V03:K1:5Zlu4vBjOn8y3rhK/v7xJFB3kzVjuBnaLVTVepoXE3uf2IfFtqB 6rHVkvjJnEO9/UjDh4AgBecn1KYpjrdkyYpVByNrgF+lPLy6EhBHUwttNktZ3HbbeWAY2WZ ynEcS9grOUky6y9Lp7PKZHfuvoi7y2yUIAbBhDW+E2l1Vsw6ZCmN0SawMeLTX7aaB1iirtb IJSPvsHD6I4Ry1wVjcZig== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:iocNUSrfeNw=;wYkjPLwi2LIAvzmFQCTm/TVNKNP dySDCNs/XyI8mriI9wR/iF0jYz36JlM7n4uOAlurxXlRCek9gBOiFIB4DPPXou0jXevH3ao4E Xf1u50XGvq8y7rjPJkSoJ6d+LELHTsmWYthxYMkHtBxRq/ANC3OCHy0uAI+RuuTCGORLDGLxo dZ3pJYhcbIMIGaU0w8sikQ/Fh10GhCu3FHR5XDP1O6zRs+K3O3zFk8z/YwEdMIowxBIWioBco DY6oUDExpJtAhyExNYuia88lcq3I+uUU2pVj2AM9iygDwQ2ZsdmgowuktDtsGzG0b/ZLADVUR QZWswuvVh7GXTGiukDJz3hIoW92R1dLQQc0fBB9r8VpzKustixfEIblNY/+oznttG0dHfvCRU ETRz2J3h0/pM/4RIZdfBRwwWnUCMZkGZcSeOpjVDYV5Dv/DT+cZ9gDNX5WPE3LyEXoVxP6ebp fVw8OKY74NAL5VJkUsUMpolCNOxhe/lJsHVtipS2CZV8A9nRMnTtzhsg5/IYdq5/X+W/H0uX1 CTEHoQGXbZn/QqUAtAcm2W53Kb2YBHP7pkaXEGiPzc7ibeEjEk55QYU0FUaF9Kxoy/05HGwVh R49G5+LYIIhoO2+YGY4pRkXqYBSHCgV+VWGu7Ht4yXCgEIYI+H/exhGOjbBzyJk6q8dwVgi+x 2CCEzxT0B+O1v0p+sCFqiV9+fEthbUCTUIVYUtokvxro/4N9Mcox1ArD0a1KEyBbrIt+HsB3D VKEhkDIMAHKCKSaa8Am/FZOL4kGUJ/lQTbrYrWqfi8MlrlOS1NW9XaxdmRHtuEWnXyaPAgrxQ //78P2kKxNwxGGT0YMqZtAh73NUtZHsHqpMvgqcRwav8/gHR2SpVtLojRZ26IslwieeL69c+f e1d8+55MqT1lMAqYo60S1ZZrJAIXHM01vDHTXOoyPnDUQpiJvuq6eJvU1jei1BFT+a/ShrKuM jrI4PA== X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786181960688352494 X-GMAIL-MSGID: 1786181960688352494 From: Markus Elfring Date: Sun, 24 Dec 2023 11:15:27 +0100 The kfree() function was called in up to three cases by the of_omap2_apll_setup() function during error handling even if the passed variable contained a null pointer. This issue was detected by using the Coccinelle software. * Split a condition check. * Adjust jump targets. * Delete three initialisations which became unnecessary with this refactoring. Signed-off-by: Markus Elfring --- drivers/clk/ti/apll.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) -- 2.43.0 diff --git a/drivers/clk/ti/apll.c b/drivers/clk/ti/apll.c index 93183287c58d..929c021f0cdb 100644 --- a/drivers/clk/ti/apll.c +++ b/drivers/clk/ti/apll.c @@ -338,21 +338,25 @@ static const struct clk_hw_omap_ops omap2_apll_hwops = { static void __init of_omap2_apll_setup(struct device_node *node) { - struct dpll_data *ad = NULL; - struct clk_hw_omap *clk_hw = NULL; - struct clk_init_data *init = NULL; + struct dpll_data *ad; + struct clk_hw_omap *clk_hw; + struct clk_init_data *init = kzalloc(sizeof(*init), GFP_KERNEL); const char *name; struct clk *clk; const char *parent_name; u32 val; int ret; - ad = kzalloc(sizeof(*ad), GFP_KERNEL); + if (!init) + return; + clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL); - init = kzalloc(sizeof(*init), GFP_KERNEL); + if (!clk_hw) + goto free_init; - if (!ad || !clk_hw || !init) - goto cleanup; + ad = kzalloc(sizeof(*ad), GFP_KERNEL); + if (!ad) + goto free_clk_hw; clk_hw->dpll_data = ad; clk_hw->hw.init = init; @@ -403,12 +407,13 @@ static void __init of_omap2_apll_setup(struct device_node *node) clk = of_ti_clk_register_omap_hw(node, &clk_hw->hw, name); if (!IS_ERR(clk)) { of_clk_add_provider(node, of_clk_src_simple_get, clk); - kfree(init); - return; + goto free_init; } cleanup: kfree(ad); +free_clk_hw: kfree(clk_hw); +free_init: kfree(init); } CLK_OF_DECLARE(omap2_apll_clock, "ti,omap2-apll-clock",