Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4515898rdb; Tue, 12 Dec 2023 01:25:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IG/e5DF6nPh+9SfE8njgWYtCVIo2BkYWuFu3W6cOhiVSnIeIa4STfHudZAVC7iwIbA8RVcG X-Received: by 2002:a05:6a00:13a8:b0:6ce:6837:4fde with SMTP id t40-20020a056a0013a800b006ce68374fdemr3360266pfg.47.1702373135121; Tue, 12 Dec 2023 01:25:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702373135; cv=none; d=google.com; s=arc-20160816; b=L3ivgRLrr+Y6kGR87Sp/rB4EPRUVvydvDf2QGM+sriT66081Tbg7mG4ByJ58YEuRS/ M+GtG7CBp7Xk1vnOEzprE3A+1TvQDcoSMqqKN0y7zeStsCywISzeIRDzbE8mdPkQoy64 lJsd6Cp+5Q0DfGbAMrufzcEnsZ+860kMdrk2aKD4c51xClAFU2tyPjPLZ/TerLN0ujSG LhuyFvCra3NbUXOG2oYx5WtvUus9U9lyElD2a/q9T1LiyFyihqpuHN+GrRdJqKiyL52T x7VMJDmSwAPyws/cRUtt7N4PccaBmjb9Ru+X04yVVy54lq3HkJcsrMM178oWWSETa23L dvtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=RumcoQW97yFH5W+dwlnMXytMhVRom0o7onaGIcSec3o=; fh=yhJFx7TMv9Mv1nl51MCJQ1D6OXbhEuX+9YSl2I8fgm8=; b=gbrVNzyrXayk1Lkv1mZKifg0o8sXcBaVQpL6SC4sTP503KEGhG+f02GaMUwYoL44bK Pzbprk0u8AlqPeFZTIDqWQuHsmwUAIqWWSqIBQ0yB8HELJwCDvSGfolkpZiPAOs0dYXt bJfMcoUyYp8fDipX7Ur7kAoQ6MRjJw8oeGJkzAFOQtXl1Nn8BxXY7NxSdwbz42lCAuqo bFGrG+urx8gPQRsONJdAyfHGCoMcquowhzOKNCxHx5CKcdjllYOExQjH17t67AdmP0Fs P4iFaOjJ8ABq2WVIm/EkV61l6+fle/A39Ps85iPFWYbrIKFrXTcG5o5O4iLfybrmWtHN r3WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OPqZu26n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id a18-20020a056a001d1200b006ce64b59396si7506076pfx.135.2023.12.12.01.25.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 01:25:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OPqZu26n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 8FD83809ABD6; Tue, 12 Dec 2023 01:25:33 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346261AbjLLJZX (ORCPT + 99 others); Tue, 12 Dec 2023 04:25:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231674AbjLLJZX (ORCPT ); Tue, 12 Dec 2023 04:25:23 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A885CF for ; Tue, 12 Dec 2023 01:25:29 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9DAE7C433C8; Tue, 12 Dec 2023 09:25:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702373129; bh=ZasmtT7TxADK9iKWNQUX4f/H8ytsR1Wy0D+0pd2020k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OPqZu26ngIhYAQXLvflLS7BxjC/5LWpSacX2uAK0MXS4GkVZE8VhgAtf/Usm3LtBF piG+WAXZhXkni2D22yDexjWcqtk2bsoGLqd5Mn84QLtFsI1ystxZf6fxDOEaBGhGX+ TSapg9F+J0kXAG2CDs0D9TY/I4ByKq1pjrgXt7g4p3Feu3IUO/7r9Jfp0SUam3D2DG 3UGRs9ZVyRIePQ5+EjeueXPbbugxyAQk46sGvB+SPC49TLyFTo4y9WMyq8E9eAbHqp 7ZyDc0pqwR/n7YQoAavaraO3HLm88w+P3iBXX61LIQDnOPBceJLuMJbO70LLjCDKKq WPHNl2DkKRDZw== Date: Tue, 12 Dec 2023 09:25:24 +0000 From: Will Deacon To: Kunwu Chan 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 Subject: Re: [PATCH] drivers/perf: Fix some null pointer dereference issues in thunderx2_pmu.c Message-ID: <20231212092523.GC28174@willie-the-truck> References: <20231211090347.265240-1-chentao@kylinos.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231211090347.265240-1-chentao@kylinos.cn> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-4.4 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_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 12 Dec 2023 01:25:33 -0800 (PST) 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