Message ID | 20230530093913.1656095-8-claudiu.beznea@microchip.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2058151vqr; Tue, 30 May 2023 02:52:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5AXhszRK0c/oklmyyKqAgh/zpPpoo68syINo399yw0lKfG2Ty34xCTnQwoFX5RvW5p0AMn X-Received: by 2002:a05:6a00:21d6:b0:63d:2d7d:b6f2 with SMTP id t22-20020a056a0021d600b0063d2d7db6f2mr1557659pfj.4.1685440374611; Tue, 30 May 2023 02:52:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685440374; cv=none; d=google.com; s=arc-20160816; b=mvBRJ+5UYo+M+wI/1lKxmC3G3yMutUT8gD9WfiMo5z4ZATvn72UsVYlUHrKvCnDNOd U4gXM/2mjI4Y0pMmOedO5FbINZ4m6oQ9tbpHcPCXv7gPSQLTe0iSMGC3Beg49QQcrjs8 FGcEl6uh5P+ZOoXA9A/EphaCIDzoCVX+enQW+y7lrTpi9rNIizUYZIXIPQSE4fU/QybE ZQtj/EVN7QFgylyaqvz7TutGR8vR8z2zbuw3YDNxHaF1ejRwq7IpZY6Ye2sHALwI1LjS jlKShyxPHNPbcz0l1vp2Z54n1nkhEwlkeMuiOEZcorKHdbq0bgweSpJN8/1jbObByB6t dFZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DNmbn4ZlEn6P4pedOdJ82uWPjoDLGSQd52I+BGBdOfU=; b=wNzPt4S8/6+PrnBueyCDWAVL9sTy/b7Z8RzWp569l3KJulGNGXI5KQiElX7p3KIVZZ KNC22iZ+jZ6jy9SXcPu8QNE6T8m444t7ImGHKzLblEiDKOY2LE8kfpi6E2+zQsMecHoh hvmA1Lc/t9s2Tv3UceXs1ZB+5n9ZEFa9ZG8ICJehTeSebskZ0LM305oukpgzt0zAzwKA VtmXWBO+uanHfUEUTiKKyZWJ7L4w8to91X1r9O26z3dAVO7lMGNSMth6dDJ5U4aZKgcA J30nA5R5SjYWw77cgKJn5KoPY0fBLeddEziSf/5NZd2/g27sleUizYFIFn0hcHfEV3Ki sD5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=e2j1C+8O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x3-20020aa79a43000000b0064f6a531c88si1402168pfj.323.2023.05.30.02.52.38; Tue, 30 May 2023 02:52:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=e2j1C+8O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230307AbjE3JlV (ORCPT <rfc822;andrewvogler123@gmail.com> + 99 others); Tue, 30 May 2023 05:41:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231255AbjE3Jkq (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 30 May 2023 05:40:46 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CC36EA; Tue, 30 May 2023 02:40:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1685439622; x=1716975622; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nxrrZgHgB/r7B5X5lLa7hKpzs6DxYZu4C3x1MeJ23Yc=; b=e2j1C+8Ovonc0fF0beuVcwoAhChnhp4Y4A9XXCyUpyTQulZZTu7LnCDN lGfPcC8RAiHMLIv2gZyPiT7k/NqzPHhf6Odq9qBDigGBUP+Flzd+XsdN2 F3VEztRfallxTK5GRngQ09VK35JbqtKoHHpjdjsljFz7RGD4X+W32fSwt c4bQUPHxcxPW0tqiugI//VypOkaDzHmJD0jlGDg7wfBIR2Ucu73AXoeFm CZ9yo7VpH9aeT3ansNd+rffjc8BzTGZGmkOIFYZgV0jDyCxKqBMBhFl2b hBDAlNBDh6453W5y53Awt5grcJ68DLwQcKDfgC84QUdob00BF461Ctwxv w==; X-IronPort-AV: E=Sophos;i="6.00,203,1681196400"; d="scan'208";a="213686540" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 30 May 2023 02:40:15 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Tue, 30 May 2023 02:40:10 -0700 Received: from m18063-ThinkPad-T460p.mchp-main.com (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.21 via Frontend Transport; Tue, 30 May 2023 02:40:06 -0700 From: Claudiu Beznea <claudiu.beznea@microchip.com> To: <mturquette@baylibre.com>, <sboyd@kernel.org>, <luca.ceresoli@bootlin.com>, <nm@ti.com>, <kristo@kernel.org>, <ssantosh@kernel.org>, <michal.simek@xilinx.com> CC: <aford173@gmail.com>, <mike.looijmans@topic.nl>, <robert.hancock@calian.com>, <shawn.guo@linaro.org>, <fabio.estevam@freescale.com>, <linux-clk@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <linux-arm-kernel@lists.infradead.org>, <linux-omap@vger.kernel.org>, Claudiu Beznea <claudiu.beznea@microchip.com> Subject: [PATCH 7/8] clk: ti: clkctrl: check return value of kasprintf() Date: Tue, 30 May 2023 12:39:12 +0300 Message-ID: <20230530093913.1656095-8-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230530093913.1656095-1-claudiu.beznea@microchip.com> References: <20230530093913.1656095-1-claudiu.beznea@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767312326007582512?= X-GMAIL-MSGID: =?utf-8?q?1767312326007582512?= |
Series |
clk: check memory returned by {devm_}kasprintf()
|
|
Commit Message
Claudiu Beznea
May 30, 2023, 9:39 a.m. UTC
kasprintf() returns a pointer to dynamically allocated memory.
Pointer could be NULL in case allocation fails. Check pointer validity.
Identified with coccinelle (kmerr.cocci script).
Fixes: 852049594b9a ("clk: ti: clkctrl: convert subclocks to use proper names also")
Fixes: 6c3090520554 ("clk: ti: clkctrl: Fix hidden dependency to node name")
Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---
drivers/clk/ti/clkctrl.c | 7 +++++++
1 file changed, 7 insertions(+)
Comments
* Claudiu Beznea <claudiu.beznea@microchip.com> [230530 09:41]: > kasprintf() returns a pointer to dynamically allocated memory. > Pointer could be NULL in case allocation fails. Check pointer validity. > Identified with coccinelle (kmerr.cocci script). Reviewed-by: Tony Lindgren <tony@atomide.com>
Quoting Claudiu Beznea (2023-05-30 02:39:12) > kasprintf() returns a pointer to dynamically allocated memory. > Pointer could be NULL in case allocation fails. Check pointer validity. > Identified with coccinelle (kmerr.cocci script). > > Fixes: 852049594b9a ("clk: ti: clkctrl: convert subclocks to use proper names also") > Fixes: 6c3090520554 ("clk: ti: clkctrl: Fix hidden dependency to node name") > Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com> > --- Applied to clk-next
diff --git a/drivers/clk/ti/clkctrl.c b/drivers/clk/ti/clkctrl.c index b6fce916967c..8c40f10280b7 100644 --- a/drivers/clk/ti/clkctrl.c +++ b/drivers/clk/ti/clkctrl.c @@ -258,6 +258,9 @@ static const char * __init clkctrl_get_clock_name(struct device_node *np, if (clkctrl_name && !legacy_naming) { clock_name = kasprintf(GFP_KERNEL, "%s-clkctrl:%04x:%d", clkctrl_name, offset, index); + if (!clock_name) + return NULL; + strreplace(clock_name, '_', '-'); return clock_name; @@ -586,6 +589,10 @@ static void __init _ti_omap4_clkctrl_setup(struct device_node *node) if (clkctrl_name) { provider->clkdm_name = kasprintf(GFP_KERNEL, "%s_clkdm", clkctrl_name); + if (!provider->clkdm_name) { + kfree(provider); + return; + } goto clkdm_found; }