Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5730639rdb; Wed, 13 Dec 2023 18:58:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IE67Ay+QwFpNZ5cHn8F7yBhaHikJqZUzvoa0pAUsPqCjeZ772XsSCCCQ8BeKecSUCIDFKI+ X-Received: by 2002:a05:6870:7d19:b0:203:234e:9bb5 with SMTP id os25-20020a0568707d1900b00203234e9bb5mr2633824oab.38.1702522685674; Wed, 13 Dec 2023 18:58:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702522685; cv=none; d=google.com; s=arc-20160816; b=bdOt9DFpBWAAWPviUrLr33fGO29FauyR4QZmYtfvt4QSUjrWcf/lSK92/usBplXmK4 ccOsx/beFQF4T4jD9ZwhvXzRwP1w92iTBA2KntxOosp3cZEvR8zOm3ltsHMhSWKRiNHH G63epF5ZslSCilgjKMthhgMFDk2E0v+VJFmJ4RY1Gf0/7Na5Cqst29tTCV7KbOoH94k5 R1yBFNU4V//EORefwSP/bXlL38HhpPspDZehUaWCWsMRdwaJUubw7jte3Hb6PtOVU/nA yBE19VcfP/RjfuND1VE2J8y6FR/1Vz5gzZ5itxSWwnKRw1D1L6fTlj4YnmvBhUAqjOAl 8Idg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=wia8Ko9q9AH44mJdsa/ZziqSMAgdu3Uy3gkA++uEc7s=; fh=fF6X4tfaJySuungZf0uIMC/paYc4Bz/1kA0XWaYRqtM=; b=FX2TenO2YJK9Bs8pz4KttE3yzIVJXfXuEmifhE/ubkxXUbedwf6Rj/XMtw3tP/y5zs HOdxPiAyoFcT9MqzJglGv0qItyAOD7PK1RPUqVy4nryT603t2+PQ2XNAbSwdOyEWjaO3 GgKfGppqb0GiRrHOcfzA+Kyy7A6hdGEAPn5UKnZccUtzU2IwMGxOuNveu9DJcwCb2l58 trDe+TrlCpwhpJO5xpDO9XhlRyXn7McGLV5uJlLqN1WpnGB3Xn/vg9HZlOqF7bvTnEfg nUbhKtE2vey/xGxWeId0MFrrHIHE+wSYchLXujHJKVtO6mMHAfHNOoYeys5MjB+O3+S2 h1FA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id i23-20020a635417000000b005ca5619a761si1169723pgb.397.2023.12.13.18.58.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 18:58:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 1187A82A856F; Wed, 13 Dec 2023 18:58:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443007AbjLNC5t (ORCPT + 99 others); Wed, 13 Dec 2023 21:57:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229739AbjLNC5s (ORCPT ); Wed, 13 Dec 2023 21:57:48 -0500 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0131FE8 for ; Wed, 13 Dec 2023 18:57:51 -0800 (PST) X-UUID: 7287c9da24384222a37dc75100d2e0a0-20231214 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.33,REQID:9a133655-a489-41ce-8782-2516dbf6c0e1,IP:15, URL:0,TC:0,Content:0,EDM:0,RT:1,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:1 X-CID-INFO: VERSION:1.1.33,REQID:9a133655-a489-41ce-8782-2516dbf6c0e1,IP:15,UR L:0,TC:0,Content:0,EDM:0,RT:1,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:1 X-CID-META: VersionHash:364b77b,CLOUDID:22f1a5fd-4a48-46e2-b946-12f04f20af8c,B ulkID:231214105741G5LGQI09,BulkQuantity:0,Recheck:0,SF:66|24|17|19|44|64|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,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_ULN,TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD, TF_CID_SPAM_FSI X-UUID: 7287c9da24384222a37dc75100d2e0a0-20231214 X-User: chentao@kylinos.cn Received: from [172.20.15.254] [(116.128.244.169)] by mailgw (envelope-from ) (Generic MTA) with ESMTP id 381816646; Thu, 14 Dec 2023 10:57:38 +0800 Message-ID: <9586be60-35f9-401f-b473-b16e86d13d07@kylinos.cn> Date: Thu, 14 Dec 2023 10:57:38 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] drivers/perf: Fix some null pointer dereference issues in thunderx2_pmu.c Content-Language: en-US To: Will Deacon Cc: mark.rutland@arm.com, Ganapatrao.Kulkarni@cavium.com, suzuki.poulose@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Kunwu Chan References: <20231211090347.265240-1-chentao@kylinos.cn> <20231212092523.GC28174@willie-the-truck> From: Kunwu Chan In-Reply-To: <20231212092523.GC28174@willie-the-truck> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Wed, 13 Dec 2023 18:58:03 -0800 (PST) Thanks for your reply. After read tx2_uncore_pmu_register again. From the defination: 'char *name = tx2_pmu->name;', we could know 'tx2_pmu->pmu.name' equals 'tx2_pmu->name' The difference is that a new memory space is allocated for 'tx2_pmu->pmu.name'. If 'tx2_pmu->pmu.name' is always the same as 'tx2_pmu->name', whether we should use 'tx2_pmu->pmu.name = tx2_pmu->name;' to replace the 'devm_kasprintf'. I'm not sure it's appropriate to do that. Thanks again. On 2023/12/12 17:25, Will Deacon wrote: > On Mon, Dec 11, 2023 at 05:03:47PM +0800, Kunwu Chan wrote: >> 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); > > AFAICT, perf_pmu_register() will WARN and return NULL, so I'm not sure what > we gain from the additional check. > >> } >> @@ -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; >> + } > > In the _highly_ unlikely even that devm_kasprintf() failed to allocate, > shouldn't we get a splat from the allocator? I don't think it's useful > to print another message. > > Will