Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp1924209lqz; Tue, 2 Apr 2024 01:38:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUXO9YFjgr92WRyr1c9mFvirOf3dN74VCiv2Uzu4C23a/vvMsHVkmbDqr+u2/NQHV2RAKzL/M+WV+LIJ3B6yZSCzPEeGBcPLIt/RFc6fA== X-Google-Smtp-Source: AGHT+IEVDzxP5uzxK7pJ7bwRcKpJoI1+Z9yGxJwUOPkc5izpjY7Dm9WXbAJrUPqeNKNrcACqiZlX X-Received: by 2002:a0c:f7d0:0:b0:696:79f1:c637 with SMTP id f16-20020a0cf7d0000000b0069679f1c637mr17922044qvo.25.1712047129629; Tue, 02 Apr 2024 01:38:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712047129; cv=pass; d=google.com; s=arc-20160816; b=is9ZpnHcR0dpunSRbhoZBpw9WD+X47hFQbcCZlffxlVWdd/XIHYJvD9DVZFpCqpMFS ns4xVaXvbHsx1L1kSwAf8zW8ApCzEUnDV45adJFhYCe71Bpu6JF8X0VjoMfo320Sb7Ag DmzgH5vfmWv6D4K0rwgOmexW8CWq8xb9PanCltGSHC4/8owtG9ryr+fsehzYxRbHNSQ6 aBBNBg93JLfjtddR8Nm4JJIj9ZXIzHTe8wwFhijL5Lf0cmrDIQOjtdYsnwT0QAM8c5kX uJ+y+JdmHUsawGyb6TUA2zczrfs6bcQd0Fh31BJeo1/1V2sphPQPkJn1P+ofmkaCiet3 vJ3Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=QWFIDo8uNi5N19faEN4Jzi+Oydfj/ZW+BIhA6AJHRrU=; fh=qB8/7n+GMZ7f4w6oWIfQzzz3ToYSgOUiacSqewoJVXk=; b=RHQ3y6Krc+auVxc4Im2G2gN8rxo8T8HbWqwTXOnER+LjSAO+Jusyctp7oclp3N3pk/ vUfjnK5W0UkzYS6CX3eaghwCCx9AOpFdp4sQZ/DXO7w3FY3kzYYkubv5YIBAdrCyJSyu 0tRIY9tlZtmWF0hiB7dnukFxDK4AgLakFWD2X0c6EEV/Bqnqb597ISHHPKni4elxiVoD 29T74GRRmwZ1U7hq9ey9gOLcpRrwj0XpsacrG5Wt6ZcVnD3Uwf+Vn4+OJSBASTWnFnHE E9BPUVsNSRj//Rdut0gJXZquy5WixqyyT5NlVhS7hVYMzoJxaVAP25uQ8orP9s3eMfBD rjjg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XII0Ga5o; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-127570-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127570-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id y8-20020ac85f48000000b0043143cd3c05si11662871qta.414.2024.04.02.01.38.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 01:38:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-127570-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XII0Ga5o; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-127570-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127570-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5D4461C21A68 for ; Tue, 2 Apr 2024 08:38:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 90D4E45BF9; Tue, 2 Apr 2024 08:38:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XII0Ga5o" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0FF58BF6; Tue, 2 Apr 2024 08:38:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712047119; cv=none; b=iTKLUjPhf7QLYWvaA1u7P3B/vIFGHXG/YYEhbzZVGM/hj2F+p6FmuFZT49HGzhAxKh78Y5OVHZgu2w0UoAxeqZhDYve1xiHrQ3CyhaLJXbfD7Ydw2O46J4bqTarVNArtewawnSVVRUO+5K1lU5ptvahEqBa8A5nZOgBCnx/wWQI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712047119; c=relaxed/simple; bh=2QTJJkBJfOudjF9f8FhQEELqqdByRxvxWBK8+NHb4b8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Y4p5B83ZxNR+6GsJrGchjJx5qDnCFs/5tpfHFYGSHbtcfw6OnL8QbC6+CVh28qcxz/llZVcwKCBUGSNUxSllyMQ+6YbW+V5EhSEBrzXQ9mW6kbs55Omaug5WFPImT2EhwgC+3pPEUkMLGjOCREK+yxFRkxBGL+mGEKz9sZ6IgQg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XII0Ga5o; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF496C433C7; Tue, 2 Apr 2024 08:38:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712047119; bh=2QTJJkBJfOudjF9f8FhQEELqqdByRxvxWBK8+NHb4b8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XII0Ga5oYDoW2nnQnppjresLqDDVdZYrBFueH+DJrzs5nFOC3bB+N310FX6Zcy/Lh Ne7h/2yrnOw1nr+tmKqmpGjVF5sxqgeInuuNIN9LtLOWNPErw7Nt1d43pRLLEEz1iT eyCEHeKVoi2IrKRDhaJlUvPupz+7DM1GOkXCrkCK7PzOezhOpCTZJweaHbWzyGbXLS 8wAy+VpJgaVDNsOODwK9eZ1in2srnNN1M0EBSYoG2HmThVRUQ5rc5OFaaaJHXrnpIs 8LXzQPdGM6F/t0h7BYZaizArYUmn70YSCm9OCCl58g4NZRd+Zsy1ybLTZpAHMd5RAy hC5jcXeWECqMg== Date: Tue, 2 Apr 2024 11:38:34 +0300 From: Leon Romanovsky To: "Gustavo A. R. Silva" Cc: Jason Gunthorpe , "Gustavo A. R. Silva" , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH][next] RDMA/cm: Avoid -Wflex-array-member-not-at-end warning Message-ID: <20240402083834.GF11187@unreal> References: <20240325224706.GB8419@ziepe.ca> <5c0bb827-e5f3-4178-ad46-8ac9b99d7726@embeddedor.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5c0bb827-e5f3-4178-ad46-8ac9b99d7726@embeddedor.com> On Mon, Mar 25, 2024 at 08:57:08PM -0600, Gustavo A. R. Silva wrote: > > > On 3/25/24 16:47, Jason Gunthorpe wrote: > > On Mon, Mar 25, 2024 at 02:24:07PM -0600, Gustavo A. R. Silva wrote: > > > -Wflex-array-member-not-at-end is coming in GCC-14, and we are getting > > > ready to enable it globally. > > > > > > Use the `struct_group_tagged()` helper to separate the flexible array > > > from the rest of the members in flexible `struct cm_work`, and avoid > > > embedding the flexible-array member in `struct cm_timewait_info`. > > > > > > Also, use `container_of()` to retrieve a pointer to the flexible > > > structure. > > > > > > So, with these changes, fix the following warning: > > > drivers/infiniband/core/cm.c:196:24: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] > > > > > > Signed-off-by: Gustavo A. R. Silva > > > --- > > > drivers/infiniband/core/cm.c | 21 ++++++++++++--------- > > > 1 file changed, 12 insertions(+), 9 deletions(-) > > > > > > diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c > > > index bf0df6ee4f78..80c87085499c 100644 > > > --- a/drivers/infiniband/core/cm.c > > > +++ b/drivers/infiniband/core/cm.c > > > @@ -182,18 +182,21 @@ struct cm_av { > > > }; > > > struct cm_work { > > > - struct delayed_work work; > > > - struct list_head list; > > > - struct cm_port *port; > > > - struct ib_mad_recv_wc *mad_recv_wc; /* Received MADs */ > > > - __be32 local_id; /* Established / timewait */ > > > - __be32 remote_id; > > > - struct ib_cm_event cm_event; > > > + /* New members must be added within the struct_group() macro below. */ > > > + struct_group_tagged(cm_work_hdr, hdr, > > > + struct delayed_work work; > > > + struct list_head list; > > > + struct cm_port *port; > > > + struct ib_mad_recv_wc *mad_recv_wc; /* Received MADs */ > > > + __be32 local_id; /* Established / timewait */ > > > + __be32 remote_id; > > > + struct ib_cm_event cm_event; > > > + ); > > > struct sa_path_rec path[]; > > > }; > > > > I didn't look, but does it make more sense to break out the path side > > into its own type and avoid the struct_group_tagged? I seem to > > remember only one thing used it. > > > > I thought about that, but I'd have to change the parameter type of > `static int cm_timewait_handler(struct cm_work *work)`, and that would > imply also modifying the internals of function `cm_work_handler()` (and > then I didn't look much into it). So let's try to invest in this direction first before we add obfuscation with magic words to the code. Thanks > So, the `struct_group_tagged()` strategy is in general more cleaner and straightforward. > > -- > Gustavo > >