Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp490163iob; Wed, 18 May 2022 06:40:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzfjSzucJADp6fwHKKZol/93ondONO5OIPZ1tq4FoWtNAoFdkBJR9XsZJPQpLkJVzgQcPY X-Received: by 2002:a65:6c10:0:b0:380:437a:c154 with SMTP id y16-20020a656c10000000b00380437ac154mr23604334pgu.549.1652881233166; Wed, 18 May 2022 06:40:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652881233; cv=none; d=google.com; s=arc-20160816; b=BkJDTdSJYklgiLILvkPCHG/+KOuOX3D8gSdqHdB5GvsB/n4SXeJIyzaaPyXn6os413 0L/K+N5nWSsxOZyXqG38Yfy25+ADBYFHMNTHyb6qhjbA9NgYEmgVo3CG32NQeZxjPPUt 0z450iHuQPbH5kQPmSahTIHsAu4GlXTgJD5ceuJIkUKm6e36uZf8ju+/KLSOr6zs1rpR je2jLuZis+wvj7TKkJ/UcQ/qZ021EHUQ/TwCwWrWJkoJly3wLNxMuNFvOh+zgNme9hiu Enr0RC5omC77lAcWJ01hcxQrvngd6rF1JMEaEJqaRtVXLhg2MCzsESjEAF7BYQLHNbpz xx2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Q3WZgKKaJOpFSnOQd5s/Qk9hzsXPqC0tIeC7GuDRMC4=; b=TEYnZTMOOlj2MttsSZuArTYnOf1m791VQAuVKfnLrHYjRX58zLDCD9/6lXst32jmNd 6QaEwzUPzMSsStljzqxKujFip+L5rw/9YYqhjtjYTWX6n74+Uc0Nfjn2iJk5DQ0uphgO ZzpeknTaaRftMbfTIe3jXc7ROScYtEJSsqyBBGNMO6TxQqSurc74eX7E3cAqSX0Sdby0 rgC0j+/uxuvk6NMrpN60IHh/e+/4/br3U3kcWDdfSkRWHubS9vTaV3wgTubfiAnJl2Ja +ZqCRmchsnI9oS9bIh+G5DijzD9soXZTgSpvnWOlW8iLjxWE9wdf7wVYVWMVXbozMCyr DDcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qBhRzGBk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id q9-20020a63ae09000000b003c208b61727si2602270pgf.822.2022.05.18.06.40.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 06:40:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qBhRzGBk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8688E18DAEF; Wed, 18 May 2022 06:40:16 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238078AbiERNkB (ORCPT + 99 others); Wed, 18 May 2022 09:40:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238056AbiERNj7 (ORCPT ); Wed, 18 May 2022 09:39:59 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A18171BE11D; Wed, 18 May 2022 06:39:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5296DB820BF; Wed, 18 May 2022 13:39:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9E96C385A5; Wed, 18 May 2022 13:39:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652881195; bh=YAGu07lD7nk9Sec8Z4RqDJGNVMRvtX91QuhoK9EteBM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qBhRzGBkhJ/WS21W8UymKR/Yj7C9/5Idf0bT5jKtz2m/7qX77Ydy3/D/Gxt8mpFAy m7Gn+S6iy7zsm/GjIuSiU5gYw/mQHit5V4radJO3h6m0NTmPcjR+sxljfoKN/zCRsn gLo0ACR7qA1u9iAjrB+Yw5DroprSEp96IOtSkJPmxN5JTuO2iTv7ki6DofkfRFdJss DwK2WK13qd4UTb65ZRR13MQedDzJIYWleNj5RI/J7Cn9rJdMMwFprNq6gWogWl2HmX dDjSgKkTOwo+xaOfo9hILAgFvEW9QbTfTvUxOLuca4HAMquqajnPjg4tIBzoIgIFQj mZRdk6/KEVTvw== Date: Wed, 18 May 2022 08:49:20 -0500 From: "Gustavo A. R. Silva" To: Lin Yujun Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, johnny.chenyi@huawei.com, chenjiahao16@huawei.com, chenlifu@huawei.com, lizhengyu3@huawei.com, liaochang1@huawei.com, wangzhu9@huawei.com, xuyihang@huawei.com, chris.zjh@huawei.com, zouyipeng@huawei.com Subject: Re: [PATCH -next] x86/events:Use struct_size() helper in kzalloc() Message-ID: <20220518134920.GA8361@embeddedor> References: <20220518131626.109123-1-linyujun809@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220518131626.109123-1-linyujun809@huawei.com> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 18, 2022 at 09:16:26PM +0800, Lin Yujun wrote: > Replace sizeof() with struct_size() to avoid potential integer > or heap overflow. This is not exactly what the patch does. Your patch is replacing the open-coded calculation of the total amount of memory to be allocated for rapl_pmus with struct_size(). > > Also, address the following sparse warnings: > arch/x86/events/rapl.c:685:16: warning: using sizeof on a > flexible structure This does not address this warning because struct_size() still make use of sizeof on the struct-with-flex-array, internally. So, the mention to the sparse warning should be removed from this changelog text. > > Signed-off-by: Lin Yujun > --- > arch/x86/events/rapl.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c > index 77e3a47af5ad..c7e79f0ac04f 100644 > --- a/arch/x86/events/rapl.c > +++ b/arch/x86/events/rapl.c > @@ -685,7 +685,7 @@ static int __init init_rapl_pmus(void) > int maxdie = topology_max_packages() * topology_max_die_per_package(); > size_t size; > > - size = sizeof(*rapl_pmus) + maxdie * sizeof(struct rapl_pmu *); > + size = struct_size(rapl_pmus, pmus, maxdie); > rapl_pmus = kzalloc(size, GFP_KERNEL); It seems that in this case, size could be entirely replaced by struct_size(). Thanks -- Gustavo