From patchwork Tue May 30 09:39:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 100704 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2058039vqr; Tue, 30 May 2023 02:52:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7U6uoeHYFgZCzg5CMgGRmmtS1O5V7XJfgJAyUXc2pPXYsJsYAwDngtvuD7scm3UL47N2AZ X-Received: by 2002:a05:6a21:170c:b0:111:97f:6d9d with SMTP id nv12-20020a056a21170c00b00111097f6d9dmr1523056pzb.62.1685440355836; Tue, 30 May 2023 02:52:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685440355; cv=none; d=google.com; s=arc-20160816; b=GkZmfJ73xgjZt0Tg1k7Otzuv8Ocju8FtvKGoQGuK11JoaHE7RfANkON1mun4Rc6HiG NguyOq3VrOQfgfDQvXcZLdjZwsjZKGfusFQjq6irbmH9sQkRwWfZ91/p/AFx+/ehfKdP nM6GE7TDZwhUzNIhp7O4JhOXnKWNY/Eq1AMycTxjf+t22A7mU5sqxclmbYHDsHUr58Ho RbD+iVAlYHRKoKgg43zhyQ8hJosHkGgG3afFkN7n7ppa3qjY6qxp2NuKthmgIQvk8NKZ 58W5T2Bj8I6gMk0n9OiXgD8s9bJzpIweJ8mbRomIELXWpC8UGLlwbyLUPPKajvo54fDC wUJA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v1-20020a17090abb8100b00256bb961a29si1003882pjr.35.2023.05.30.02.52.22; Tue, 30 May 2023 02:52:35 -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 S230201AbjE3Jjp (ORCPT + 99 others); Tue, 30 May 2023 05:39:45 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767312306443707384?= X-GMAIL-MSGID: =?utf-8?q?1767312306443707384?= 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 Reviewed-by: Luca Ceresoli --- 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;