From nobody Thu May 7 21:11:39 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7EADAC433F5 for ; Thu, 19 May 2022 02:37:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232944AbiESChp (ORCPT ); Wed, 18 May 2022 22:37:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232008AbiESChl (ORCPT ); Wed, 18 May 2022 22:37:41 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A2BB8FFB2; Wed, 18 May 2022 19:37:37 -0700 (PDT) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4L3YrY5yZrz1JCDW; Thu, 19 May 2022 10:36:13 +0800 (CST) Received: from dggpeml500010.china.huawei.com (7.185.36.155) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 19 May 2022 10:37:36 +0800 Received: from huawei.com (10.67.175.33) by dggpeml500010.china.huawei.com (7.185.36.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 19 May 2022 10:37:35 +0800 From: Lin Yujun To: , , , , , , , , , , , CC: , , , , , , , , , , , , Subject: [PATCH -next v2] x86/events:Use struct_size() helper in kzalloc() Date: Thu, 19 May 2022 10:36:00 +0800 Message-ID: <20220519023600.241591-1-linyujun809@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.67.175.33] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500010.china.huawei.com (7.185.36.155) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows. Signed-off-by: Lin Yujun --- arch/x86/events/rapl.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c index 77e3a47af5ad..8da003e02010 100644 --- a/arch/x86/events/rapl.c +++ b/arch/x86/events/rapl.c @@ -683,10 +683,8 @@ static const struct attribute_group *rapl_attr_update[= ] =3D { static int __init init_rapl_pmus(void) { int maxdie =3D topology_max_packages() * topology_max_die_per_package(); - size_t size; =20 - size =3D sizeof(*rapl_pmus) + maxdie * sizeof(struct rapl_pmu *); - rapl_pmus =3D kzalloc(size, GFP_KERNEL); + rapl_pmus =3D kzalloc(struct_size(rapl_pmus, pmus, maxdie), GFP_KERNEL); if (!rapl_pmus) return -ENOMEM; =20 --=20 2.17.1