Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4273408rwd; Tue, 30 May 2023 03:04:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Hk+xrHUpR5AgTZJKCsAd7HClSGDHm72JKNxg0WQiFavtQF9bzijaf3HCyXNjRVPw3mkN8 X-Received: by 2002:a05:6a21:7894:b0:10a:e8c2:7227 with SMTP id bf20-20020a056a21789400b0010ae8c27227mr2011306pzc.45.1685441093016; Tue, 30 May 2023 03:04:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685441093; cv=none; d=google.com; s=arc-20160816; b=m6sdHIgR2SXWzXHAQLp5CXLhzb+cFvXPcIG/acD2J/w9G4HErlHk0gM/BwrEvoHQVy SEiShl/YSObDtXTgmJCJhFTPvP9OF0OuS2pgHebSFAD5lL2e7pUem935+evX40i1/CAl O0NFppUb5mtEkE9pAr3K+9RuDvx4kn7Czm3mXLUMrJ7dTbrL+KGmJWJOfmFArrDN0FEp PqftsohwF54ONxxzXXx2a/kTgQgOE/zJZwYrdfi9IpY6T+Ut8SHscMnkgLgCXrZ/tEsG 2TKvR+4Jz+3qbwjyvwNAcvzqzY84adytEkb7mO1cQzvz16ZIRydghqI7MvIPT04c7VWx e0Rg== 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=dkWeCSmv/Vo6QaEImj5hjfFICIG/XFsDd3o6ORLjjB8=; b=SbmMCCiVMamXryl4E4kYw95aLK73j3mkOpJTLbwveogaTF7OgiHuFpF8tLsJ6gOmD5 JzmyTqby+WtrXGUzW0aQD68cEiRVMYtmzdyfew3VPXSGMYoF+8K8v/KIouBZ7OoynUoL rGcnwnTmaKcv0B5KHAlGIyMVOJOSupsAYzhw/eWVKo7tIT2HiCW8ZyEoCXHVm6j711pV ek9Esrj7Kypk7fneKjENZtqBN5zdmi8tUpQ2LkPaWG5lDXaDA9W+o/+Cd1okoukrdeGo zSPqYFugXp6U+pnJddxPIE57pOaTNNwIZAYf1WfRPcZO/YAh5XOTkr7y+9TYhQG2TM8P JgWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=SBv8CAXZ; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u27-20020a63b55b000000b005346ce4f2absi708961pgo.605.2023.05.30.03.04.39; Tue, 30 May 2023 03:04:52 -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=SBv8CAXZ; 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 S230288AbjE3Jjo (ORCPT + 99 others); Tue, 30 May 2023 05:39:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229976AbjE3Jjm (ORCPT ); Tue, 30 May 2023 05:39:42 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26EE5EA; Tue, 30 May 2023 02:39:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1685439580; x=1716975580; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nmVGwDvjtH8SjM5DgD/DxYkOVw0e2bHjD/47RTMYLJM=; b=SBv8CAXZFYnUjL+0AJigD8lHNqRmysvhBmqWO7txGCU45QmrZfpQxd93 2Y2IN7dBmDbvjV0KXMoFtJZQGObECIsMpkDnMKJp+U/D5/ADe5kbKwoB7 lbppRHUS1WS5mEnG5JqBbupJw5WXVXWrobEdlmHPnUgnYMjEL0ifmrMVA llZBnTI/kHaItvpCJYDdBaGwcwx6BJ5MFqZjVSLLQNtMYg5iLysoYMvtk iqaIy6e7cpUwYMWGR5dJGgbWZrQ6bkF2Vzd5B0ShaJMa5aRWSpi4MAwng M9pN5qxophAOqFffquztK/jx1G02EwK3sZCioxR9aaa4aqqCxZSeYcFXR w==; X-IronPort-AV: E=Sophos;i="6.00,203,1681196400"; d="scan'208";a="227558484" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 30 May 2023 02:39:40 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex01.mchp-main.com (10.10.85.143) 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:39:39 -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:39:35 -0700 From: Claudiu Beznea To: , , , , , , CC: , , , , , , , , , Claudiu Beznea Subject: [PATCH 1/8] clk: vc5: check memory returned by kasprintf() Date: Tue, 30 May 2023 12:39:06 +0300 Message-ID: <20230530093913.1656095-2-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: X-Mailing-List: linux-kernel@vger.kernel.org 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: f491276a5168 ("clk: vc5: Allow Versaclock driver to support multiple instances") Signed-off-by: Claudiu Beznea --- drivers/clk/clk-versaclock5.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/clk/clk-versaclock5.c b/drivers/clk/clk-versaclock5.c index fa71a57875ce..40fdf2564aa7 100644 --- a/drivers/clk/clk-versaclock5.c +++ b/drivers/clk/clk-versaclock5.c @@ -1028,6 +1028,11 @@ static int vc5_probe(struct i2c_client *client) } init.name = kasprintf(GFP_KERNEL, "%pOFn.mux", client->dev.of_node); + if (!init.name) { + ret = -ENOMEM; + goto err_clk; + } + init.ops = &vc5_mux_ops; init.flags = 0; init.parent_names = parent_names; @@ -1042,6 +1047,10 @@ static int vc5_probe(struct i2c_client *client) memset(&init, 0, sizeof(init)); init.name = kasprintf(GFP_KERNEL, "%pOFn.dbl", client->dev.of_node); + if (!init.name) { + ret = -ENOMEM; + goto err_clk; + } init.ops = &vc5_dbl_ops; init.flags = CLK_SET_RATE_PARENT; init.parent_names = parent_names; @@ -1057,6 +1066,10 @@ static int vc5_probe(struct i2c_client *client) /* Register PFD */ memset(&init, 0, sizeof(init)); init.name = kasprintf(GFP_KERNEL, "%pOFn.pfd", client->dev.of_node); + if (!init.name) { + ret = -ENOMEM; + goto err_clk; + } init.ops = &vc5_pfd_ops; init.flags = CLK_SET_RATE_PARENT; init.parent_names = parent_names; @@ -1074,6 +1087,10 @@ static int vc5_probe(struct i2c_client *client) /* Register PLL */ memset(&init, 0, sizeof(init)); init.name = kasprintf(GFP_KERNEL, "%pOFn.pll", client->dev.of_node); + if (!init.name) { + ret = -ENOMEM; + goto err_clk; + } init.ops = &vc5_pll_ops; init.flags = CLK_SET_RATE_PARENT; init.parent_names = parent_names; @@ -1093,6 +1110,10 @@ static int vc5_probe(struct i2c_client *client) memset(&init, 0, sizeof(init)); init.name = kasprintf(GFP_KERNEL, "%pOFn.fod%d", client->dev.of_node, idx); + if (!init.name) { + ret = -ENOMEM; + goto err_clk; + } init.ops = &vc5_fod_ops; init.flags = CLK_SET_RATE_PARENT; init.parent_names = parent_names; @@ -1111,6 +1132,10 @@ static int vc5_probe(struct i2c_client *client) memset(&init, 0, sizeof(init)); init.name = kasprintf(GFP_KERNEL, "%pOFn.out0_sel_i2cb", client->dev.of_node); + if (!init.name) { + ret = -ENOMEM; + goto err_clk; + } init.ops = &vc5_clk_out_ops; init.flags = CLK_SET_RATE_PARENT; init.parent_names = parent_names; @@ -1137,6 +1162,10 @@ static int vc5_probe(struct i2c_client *client) memset(&init, 0, sizeof(init)); init.name = kasprintf(GFP_KERNEL, "%pOFn.out%d", client->dev.of_node, idx + 1); + if (!init.name) { + ret = -ENOMEM; + goto err_clk; + } init.ops = &vc5_clk_out_ops; init.flags = CLK_SET_RATE_PARENT; init.parent_names = parent_names; -- 2.34.1