Message ID | 20230725195020.3469132-1-ruanjinjie@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2431816vqg; Tue, 25 Jul 2023 05:26:57 -0700 (PDT) X-Google-Smtp-Source: APBJJlEJ5U6ILhJPOHTZZZx+fSndUrldmBYgJsd70P6JzbuelKbE3nMdqklM26B3tXzWFfHTCPgr X-Received: by 2002:a17:90b:8d:b0:268:808:8e82 with SMTP id bb13-20020a17090b008d00b0026808088e82mr449042pjb.1.1690288016851; Tue, 25 Jul 2023 05:26:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690288016; cv=none; d=google.com; s=arc-20160816; b=AJIBUAP3zEsSgyHmLgJgWIMUtR3kDT0L5WmhAP4CGsAlY16s65n1NGvg8XkHzvD0gl TLxKaBDsXfdHzilsuEHh7yabRjFjHhNCCcb0YV2I5ajhAb9AFP3Er2IhAjrpxSd8cD/S aHG2DxX8Yv/wAt3ngsKKCghN93PmfBV3Vsx3Q1M2gdX978LCWkMPnsDS0KtcUq1fWrGt +ZasB6tvNK1DwGULZXZfQj5PX0lSMWg5D3lDYNCuaTIvSJ7bDRWUtvh+LAQjNleOy3ND atEQWpkjaOdN4QfNRt0Dr8tOQFIIPzlsOuGqz07iYmRgawdEYM/8wJ9bQe1IFWHkEqaZ KT+Q== 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=LkQLIe3jyHMyTRmgGfQ9B7N9iICnIccN36Ct0ebwgVE=; fh=rX/+yvLprTS7i65VgLL5WuPE7IOCJ3QONXfMAvUUdK4=; b=YGsLZUVdkLdLAgjpabmx4p5jheIQeiNNtMYPepym0dpqQMX+XpfZWGAYtjYGY2Dp5H hxKt2KVAgInyy0O7d0AsuTPNs3Zs0clhA8yUQ+16HtUnE0AoiHHGuGmlA28JF6ENVx0S QnNdtCSyfuNgYxmZkSOwI6aVNuygNKVPg0ZktFG8q75//lv2vK0sL9S8ZlnuB0OcqjPS D29hBcUvRKtclnKzhQFpfhs7LG/wx74j0NtcTLpTOubu29Gsa2Fl7KMfQUmRUSAHGkXt ECNljkFKmeRyOqeOZLHzqlwY7MoI4Jf7Trqa9MeWevtJrYOBpAyS5ik1FQNESMF5JvJT Pz2w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l23-20020a637017000000b0055bc1f0be88si11993669pgc.219.2023.07.25.05.26.44; Tue, 25 Jul 2023 05:26:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233241AbjGYLuq (ORCPT <rfc822;kloczko.tomasz@gmail.com> + 99 others); Tue, 25 Jul 2023 07:50:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232905AbjGYLuR (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 25 Jul 2023 07:50:17 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE0762118 for <linux-kernel@vger.kernel.org>; Tue, 25 Jul 2023 04:49:58 -0700 (PDT) Received: from kwepemi500008.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4R9Fc23K9JztRl4; Tue, 25 Jul 2023 19:46:26 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemi500008.china.huawei.com (7.221.188.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 25 Jul 2023 19:49:39 +0800 From: Ruan Jinjie <ruanjinjie@huawei.com> To: <mingo@redhat.com>, <peterz@infradead.org>, <juri.lelli@redhat.com>, <vincent.guittot@linaro.org>, <dietmar.eggemann@arm.com>, <rostedt@goodmis.org>, <bsegall@google.com>, <mgorman@suse.de>, <bristot@redhat.com>, <vschneid@redhat.com>, <linux-kernel@vger.kernel.org> CC: <ruanjinjie@huawei.com> Subject: [PATCH -next] sched/fair: Use struct_size() Date: Tue, 25 Jul 2023 19:50:20 +0000 Message-ID: <20230725195020.3469132-1-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemi500008.china.huawei.com (7.221.188.139) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772395447245337993 X-GMAIL-MSGID: 1772395447245337993 |
Series |
[-next] sched/fair: Use struct_size()
|
|
Commit Message
Jinjie Ruan
July 25, 2023, 7:50 p.m. UTC
Use struct_size() instead of hand-writing it, when allocating a structure
with a flex array.
This is less verbose.
Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
---
kernel/sched/fair.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
Comments
On Tue, Jul 25, 2023 at 07:50:20PM +0000, Ruan Jinjie wrote: > Use struct_size() instead of hand-writing it, when allocating a structure > with a flex array. > > This is less verbose. As per all the other times, no. It is also less clear. I never can remember what that thing does and the code it replaces is utterly trivial. > Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com> > --- > kernel/sched/fair.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index f8b71ea5948b..cc041a48100f 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -2889,9 +2889,8 @@ static void task_numa_group(struct task_struct *p, int cpupid, int flags, > int i; > > if (unlikely(!deref_curr_numa_group(p))) { > - unsigned int size = sizeof(struct numa_group) + > - NR_NUMA_HINT_FAULT_STATS * > - nr_node_ids * sizeof(unsigned long); > + unsigned int size = struct_size(grp, faults, > + NR_NUMA_HINT_FAULT_STATS * nr_node_ids); > > grp = kzalloc(size, GFP_KERNEL | __GFP_NOWARN); > if (!grp) > -- > 2.34.1 >
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index f8b71ea5948b..cc041a48100f 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -2889,9 +2889,8 @@ static void task_numa_group(struct task_struct *p, int cpupid, int flags, int i; if (unlikely(!deref_curr_numa_group(p))) { - unsigned int size = sizeof(struct numa_group) + - NR_NUMA_HINT_FAULT_STATS * - nr_node_ids * sizeof(unsigned long); + unsigned int size = struct_size(grp, faults, + NR_NUMA_HINT_FAULT_STATS * nr_node_ids); grp = kzalloc(size, GFP_KERNEL | __GFP_NOWARN); if (!grp)