From mboxrd@z Thu Jan 1 00:00:00 1970 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 9B888C433EF for ; Tue, 11 Jan 2022 15:14:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245705AbiAKPOj (ORCPT ); Tue, 11 Jan 2022 10:14:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244952AbiAKPOa (ORCPT ); Tue, 11 Jan 2022 10:14:30 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A282C06173F; Tue, 11 Jan 2022 07:14:29 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id B6B81615E8; Tue, 11 Jan 2022 15:14:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93A05C36AE3; Tue, 11 Jan 2022 15:14:26 +0000 (UTC) Date: Tue, 11 Jan 2022 10:14:25 -0500 From: Steven Rostedt To: Peter Zijlstra Cc: Xiu Jianfeng , mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, gustavoars@kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Linus Torvalds Subject: Re: [PATCH -next, v2] sched: Use struct_size() helper in task_numa_group() Message-ID: <20220111101425.7c59de5b@rorschach.local.home> In-Reply-To: References: <20220110012354.144394-1-xiujianfeng@huawei.com> <20220110193158.31e1eaea@gandalf.local.home> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 11 Jan 2022 12:30:42 +0100 Peter Zijlstra wrote: > > > > 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); > > > > > > Again, why?! The old code was perfectly readable, this, not so much. > > > > Because it is unsafe, > > Unsafe how? Changelog doesn't mention anything, nor do you. In fact, > Changelog says there is no functional change, which makes me hate the > thing for obscuring something that was simple. If for some reason faults changes in size, the original code must be updated whereas the new code is robust enough to not need changing. > > > And to be honest, the new change is a lot easier to read than the original > > code. > > I find it the other way around, because now I need to find and untangle > the unholy mess that is struct_size(), whereas currently it is trivial > C. It's a C hack and far from trivial. Maybe to you as you are use to these hacks. But seriously, this is not something the average C coder is use to, as variable length structures are rather unique to the kernel. Note that struct_size() is commonly used in the kernel. Better start getting use to it ;-) -- Steve