Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp3837691rdb; Mon, 11 Dec 2023 01:04:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IGrpAYmNl1sY1uRz2HLr507+jBTVosNbqIp4yt4PPW1qulCPRu1WgcIufA6bUM/HKfeMb4t X-Received: by 2002:a05:6a20:8e12:b0:18a:4895:8721 with SMTP id y18-20020a056a208e1200b0018a48958721mr2035583pzj.18.1702285470471; Mon, 11 Dec 2023 01:04:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702285470; cv=none; d=google.com; s=arc-20160816; b=oPqExCVO0ZN1OhJgxakE/6OdPukIUFsZVbrQTfLEBcBFRxyJG5K2CXflkpOpXFWQav t/3K8z84YboUCq0R2mhqrODSSYon7Vbax4h9yUH8w6cobA0TOoMiIe4o8GAPYmldTk0Y iPhAvEjDDCJltSZHrDl4Buerxa5dV+wY/erkioV1PnUDm725tcOUnizXXTL4mx2ZIgAp 1uy7+IP1toM7V+qoHGvNkcq9T504n4FLuO5nhDBbIN/Y+O0xGYJ6mOtwDZHTSi7Uv6Mr J+RwtY86PFx20uDT7NpezDvevh3iDtDloFFN+ZA1pP4wDKhBb8LDtgc/t7ZV3synDi+R jSDA== 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=479vtfw/z/pL01Ql2gVk9s1ITQbemLkSXz8u5h8m6bU=; fh=Ppy1WHgCqs4Jl5DoImIesOZauj3QgBlpLQBY9TqgKnE=; b=B+DDCExGdp8O9hwHsD8+cSUrwdAItUQXOvULCjxmqijOuJSpf0V7KvAHNzpiYZ7y6j oSbwuQAv1coNyH6wlL73btDqN7k5sDRA6/YXHIpKt+GgvJjA8tl6k/dkI73mDg41V/VM 2uNOSiCE6OXbi5gw1uZT9Gsmuf1voOl+S1IrMCLWHrb19oYjCt5IAt1n2iwVa3r6KPA4 ZQaOw0IDVJVzgR7kkkJ6K0CEZJPk1TLiVmJ/OyhbMQ1iIQDPAjBLY9h9k5TF7iRkagO4 vQxgEag38m9+LP+nbDA7FJAW32Aln93nY0B2q8+UGIBl5cg+hA6sXpvgoNmWHeApLNtJ Z72Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id x24-20020a17090abc9800b0028a0244d5d9si5871491pjr.164.2023.12.11.01.04.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 01:04:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id AFD948094D4B; Mon, 11 Dec 2023 01:04:27 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234070AbjLKJEM (ORCPT + 99 others); Mon, 11 Dec 2023 04:04:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229608AbjLKJEL (ORCPT ); Mon, 11 Dec 2023 04:04:11 -0500 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09E9DF2 for ; Mon, 11 Dec 2023 01:04:14 -0800 (PST) X-UUID: ddb7c8ac5a7740c39319e8105f29cf2c-20231211 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.33,REQID:1d2c04cf-5843-4420-b84c-766dfd178ec5,IP:5,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-10 X-CID-INFO: VERSION:1.1.33,REQID:1d2c04cf-5843-4420-b84c-766dfd178ec5,IP:5,URL :0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:-10 X-CID-META: VersionHash:364b77b,CLOUDID:c34d87fd-4a48-46e2-b946-12f04f20af8c,B ulkID:2312111704042F6WSKZH,BulkQuantity:0,Recheck:0,SF:17|19|44|66|38|24|1 02,TC:nil,Content:0,EDM:-3,IP:-2,URL:11|1,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_FSD,TF_CID_SPAM_FSI,TF_CID_SPAM_ULN,TF_CID_SPAM_SNR, TF_CID_SPAM_FAS X-UUID: ddb7c8ac5a7740c39319e8105f29cf2c-20231211 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 1939800852; Mon, 11 Dec 2023 17:04:02 +0800 From: Kunwu Chan To: will@kernel.org, mark.rutland@arm.com Cc: Ganapatrao.Kulkarni@cavium.com, suzuki.poulose@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Kunwu Chan , Kunwu Chan Subject: [PATCH] drivers/perf: Fix some null pointer dereference issues in thunderx2_pmu.c Date: Mon, 11 Dec 2023 17:03:47 +0800 Message-Id: <20231211090347.265240-1-chentao@kylinos.cn> X-Mailer: git-send-email 2.39.2 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 fry.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 (fry.vger.email [0.0.0.0]); Mon, 11 Dec 2023 01:04:27 -0800 (PST) devm_kasprintf() returns a pointer to dynamically allocated memory which can be NULL upon failure. Fixes: 69c32972d593 ("drivers/perf: Add Cavium ThunderX2 SoC UNCORE PMU driver") Cc: Kunwu Chan Signed-off-by: Kunwu Chan --- drivers/perf/thunderx2_pmu.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/perf/thunderx2_pmu.c b/drivers/perf/thunderx2_pmu.c index 1edb9c03704f..07edb174a0d7 100644 --- a/drivers/perf/thunderx2_pmu.c +++ b/drivers/perf/thunderx2_pmu.c @@ -742,6 +742,8 @@ static int tx2_uncore_pmu_register( tx2_pmu->pmu.name = devm_kasprintf(dev, GFP_KERNEL, "%s", name); + if (!tx2_pmu->pmu.name) + return -ENOMEM; return perf_pmu_register(&tx2_pmu->pmu, tx2_pmu->pmu.name, -1); } @@ -881,6 +883,11 @@ static struct tx2_uncore_pmu *tx2_uncore_pmu_init_dev(struct device *dev, return NULL; } + if (!tx2_pmu->name) { + dev_err(dev, "PMU type %d: Fail to allocate memory\n", type); + devm_kfree(dev, tx2_pmu); + return NULL; + } return tx2_pmu; } -- 2.39.2