Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp897077rdf; Tue, 21 Nov 2023 22:48:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IFa5L6h6pXPx+B2ci0CyE2UNHVQnbD/gwYJ9OJM7TU0KE1QAj73oizSDFhoe5B8N8TnE4Be X-Received: by 2002:a05:6a20:7da0:b0:17a:4871:63fd with SMTP id v32-20020a056a207da000b0017a487163fdmr2394336pzj.0.1700635713008; Tue, 21 Nov 2023 22:48:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700635712; cv=none; d=google.com; s=arc-20160816; b=aD9akStPdpOK0axYaJL/iylA+aKleHt5LevyY/Pr7e3p1qBgvpzbnxLwKXh0pm0jTl EeeR65PiW33/Tkkcb58Q5gq+jWVFqE96bS8G84Hrbqe8kFif7E5jiMm32t3qUvl9eGh0 c6qDRjt0pgRxf2p6VmFShWaBBiwSXBS/PnZnUGXX+b78LgHE9B3iBuznh/JrUB+BiOei NiZLQImCd88k6s3EUyIp1dcYNsVoi/l2AODAJvlmNfPD8r1o9M3QVI5cG9OhDWiPaJzv g3FNPmhEWbbDye6hVn/ugM78NxYyhkQmQGk3M+LqJlFu21AZGHNFGutH4LUaFYIOcrkB PWyg== 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 :message-id:date:subject:cc:to:from; bh=ZR0YNR78sGiNpqIqMszxlWwILfnffgWIPMhMEclQTtI=; fh=EJfytRrQA6ceml1RGdRfvVOCOQTC32SQhWxjiktS4/g=; b=NJE+MNb9CIUn4mqdVegKyN212Meu5xNr13o7qDpC6IdWhxe9GU6JpjuqAOeYeJz0Dy TLjBQMKzw7ZCtZheCO344UJjH4EXnxVmbmunjfPLeGueAJOJjz/4FI7BTJ6HawAI+ewx C1s6WPXn/EzX+80YgSPrlUXuGgxPLVVy4t92Fbjn+2Ec8pq6getSUBWxXpNyRf8JdmAq j4TkiEFYik9UHFx4KRw+pPd76yEM8m+gw95p+iH1ZyRpxkMIJk8xUp2E5aEfn/mphIYJ 8UzawyL+p6n4jbDAl8HRdusvB5qgLaUHp4hfVw64y+XzzeLwoFGzicLDOBsaiC9wPazM vipQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id t15-20020a63dd0f000000b005c1b289757dsi12143954pgg.88.2023.11.21.22.48.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 22:48:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id AB9A781A2078; Tue, 21 Nov 2023 22:48:30 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232593AbjKVGsU (ORCPT + 99 others); Wed, 22 Nov 2023 01:48:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229991AbjKVGsT (ORCPT ); Wed, 22 Nov 2023 01:48:19 -0500 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9449C110 for ; Tue, 21 Nov 2023 22:48:13 -0800 (PST) X-UUID: 48b669095d8046bcaaaf4f95e7db4b1d-20231122 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.32,REQID:b32ff27c-8ab5-4f81-ae02-b0bb2d52caf9,IP:5,U RL:0,TC:0,Content:-25,EDM:25,RT:0,SF:-9,FILE:0,BULK:0,RULE:Release_Ham,ACT ION:release,TS:-4 X-CID-INFO: VERSION:1.1.32,REQID:b32ff27c-8ab5-4f81-ae02-b0bb2d52caf9,IP:5,URL :0,TC:0,Content:-25,EDM:25,RT:0,SF:-9,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-4 X-CID-META: VersionHash:5f78ec9,CLOUDID:7afd5760-c89d-4129-91cb-8ebfae4653fc,B ulkID:231122144800C0XZ0ADZ,BulkQuantity:0,Recheck:0,SF:42|74|66|38|24|17|1 9|102,TC:nil,Content:0,EDM:5,IP:-2,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil, COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI X-UUID: 48b669095d8046bcaaaf4f95e7db4b1d-20231122 X-User: chentao@kylinos.cn Received: from vt.. [(116.128.244.169)] by mailgw (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 635458510; Wed, 22 Nov 2023 14:47:57 +0800 From: Kunwu Chan To: linux@armlinux.org.uk, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, arnd@arndb.de, angus.chen@jaguarmicro.com, u.kleine-koenig@pengutronix.de Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kunwu.chan@hotmail.com, Kunwu Chan , Ahmad Fatoum Subject: [PATCH v2] ARM: imx: Check return value of devm_kasprintf in imx_mmdc_perf_init Date: Wed, 22 Nov 2023 14:46:36 +0800 Message-Id: <20231122064636.7268-1-chentao@kylinos.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 21 Nov 2023 22:48:30 -0800 (PST) devm_kasprintf() returns a pointer to dynamically allocated memory which can be NULL upon failure. Ensure the allocation was successful by checking the pointer validity. Release the id allocated in 'mmdc_pmu_init' when 'devm_kasprintf' return NULL Suggested-by: Ahmad Fatoum Fixes: e76bdfd7403a ("ARM: imx: Added perf functionality to mmdc driver") Signed-off-by: Kunwu Chan --- v2: Add new label to release the id allocated in 'mmdc_pmu_init' --- arch/arm/mach-imx/mmdc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/arm/mach-imx/mmdc.c b/arch/arm/mach-imx/mmdc.c index 2157493b78a9..df69af932375 100644 --- a/arch/arm/mach-imx/mmdc.c +++ b/arch/arm/mach-imx/mmdc.c @@ -501,6 +501,10 @@ static int imx_mmdc_perf_init(struct platform_device *pdev, void __iomem *mmdc_b name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "mmdc%d", ret); + if (!name) { + ret = -ENOMEM; + goto pmu_release_id; + } pmu_mmdc->mmdc_ipg_clk = mmdc_ipg_clk; pmu_mmdc->devtype_data = (struct fsl_mmdc_devtype_data *)of_id->data; @@ -523,9 +527,10 @@ static int imx_mmdc_perf_init(struct platform_device *pdev, void __iomem *mmdc_b pmu_register_err: pr_warn("MMDC Perf PMU failed (%d), disabled\n", ret); - ida_simple_remove(&mmdc_ida, pmu_mmdc->id); cpuhp_state_remove_instance_nocalls(cpuhp_mmdc_state, &pmu_mmdc->node); hrtimer_cancel(&pmu_mmdc->hrtimer); +pmu_release_id: + ida_simple_remove(&mmdc_ida, pmu_mmdc->id); pmu_free: kfree(pmu_mmdc); return ret; -- 2.34.1