Message ID | Y72WBTUmh9r1lvKN@work |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2855029wrt; Tue, 10 Jan 2023 08:49:37 -0800 (PST) X-Google-Smtp-Source: AMrXdXu1u4FbxqSlole1ZFgGKx/cVJeoEbplf+4n8MaUWC9HdXcbm5gPiRJs34Cqk6UsG8FRwoqn X-Received: by 2002:a17:90a:bf0b:b0:226:f10a:c0de with SMTP id c11-20020a17090abf0b00b00226f10ac0demr13157532pjs.19.1673369377272; Tue, 10 Jan 2023 08:49:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673369377; cv=none; d=google.com; s=arc-20160816; b=Lwah03BQtBwjup0c8jIGV56ngpfM9KQJoGkHb3EaG1/gZ/PIIZMqDq93+SIClI+jVJ VuX8BVsWQaHClvBgmb0plJnMRvNwCWjUDWqIc+48fTLAJnWdrJr0NDhIZeWSZ45JGPT0 gzVTCWJNL8j4VHyRhXDkUZv2f0BIwmmxb8qEPs1ZvM9kHt3p3hA99vYfwHLX1AK3JQX+ Yh1DHC50dxLCKQ8Wy5S/M1Vb/cp5na5pKR/2nrAZQ+YiOBD9HY2r0XpekwyffTWLg2TR rVu2OCa9ZA0td8y7VY8C2WwGvQzCYHOq3L6i9nKlkZKIHD0fsYmSvy85IWAeBPMXxX/s kFuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=S8hSpzsFlQpWMn9G5vdObzK5QUb7j4A3W7UPZKkbr4M=; b=F9axoomKXLnj6ZObGYOolCVaYb3hqOfXPp3bFgo8KzymMiEkoODLXAJHbaiGu2k38R 3uu/sr7HiW++xCDefOYgGUlM1zQPPvTw/zlz1bmsAxQBDB3HOjB1a9xFK+NJXLPjgchL bb+0PMO3tMeDpsC9Uj6ILyMX80QJIU+ghSvwDzLKW5aNmm+5d27Pb6UZGGZjFtp7tG0o EJYsmP73ZaCOYtMPVgasMSr6RdK721ER68MorZ/qj/K/5ZyQRiZNEQ3c7nbLiGzGdKUq 71MKoQzhGEQTN9C8k5ozZNiEX3SyAFteqgiXezRcz8YnpOzdO1mwrSDyYMwOExvNS+SG 5ujw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HI7JpEwk; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p15-20020a637f4f000000b0049699771576si12012243pgn.424.2023.01.10.08.49.24; Tue, 10 Jan 2023 08:49:37 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HI7JpEwk; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234859AbjAJQpK (ORCPT <rfc822;syz17693488234@gmail.com> + 99 others); Tue, 10 Jan 2023 11:45:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234356AbjAJQos (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 10 Jan 2023 11:44:48 -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 62E575A8BA; Tue, 10 Jan 2023 08:44:47 -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 0BC15617E5; Tue, 10 Jan 2023 16:44:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B925C433D2; Tue, 10 Jan 2023 16:44:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673369086; bh=5pn8lNPzgrol7P8MBSuD7FbH2Rhpic8YeqNAugxASls=; h=Date:From:To:Cc:Subject:From; b=HI7JpEwkuf+RJ2R7d+YsfTHRQBGCakNFWm+7b1d30HrcAcAh1p9QQmP4YXO1RXiml jR/gZjcdi/S9lCp1mHKWz9UF2qvAVC4MSw7eNLX+BkvbyA1wcr1atcLXBzCwcIoORY 6h9q2+C44XQ3YaGjgfU4qo9TQZCDFd4dXTELHiQ6v/cGxAJsqpdaidEv5Cn8CyHjiJ I9WGQy4F4ioTx1C+EhjYsc706rSMm4+I94FDxs0q/DNlBDhJSKef9pmowT1f/jCRSb pqCoJAx0aXoNfcXkf0XuF7ax9lsSySCsjp9NXhzt1zMB6KyuLS05r49mUYB5IL/PXu wcTeCnt2+yo/A== Date: Tue, 10 Jan 2023 10:44:53 -0600 From: "Gustavo A. R. Silva" <gustavoars@kernel.org> To: Jani Nikula <jani.nikula@linux.intel.com>, Joonas Lahtinen <joonas.lahtinen@linux.intel.com>, Rodrigo Vivi <rodrigo.vivi@intel.com>, Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>, David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch> Cc: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" <gustavoars@kernel.org>, linux-hardening@vger.kernel.org Subject: [PATCH][next] drm/i915/guc: Replace zero-length arrays with flexible-array members Message-ID: <Y72WBTUmh9r1lvKN@work> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754654967682005325?= X-GMAIL-MSGID: =?utf-8?q?1754654967682005325?= |
Series |
[next] drm/i915/guc: Replace zero-length arrays with flexible-array members
|
|
Commit Message
Gustavo A. R. Silva
Jan. 10, 2023, 4:44 p.m. UTC
Zero-length arrays are deprecated[1] and we are moving towards
adopting C99 flexible-array members, instead. So, replace zero-length
arrays in a couple of structures (three, actually) with flex-array
members.
This helps with the ongoing efforts to tighten the FORTIFY_SOURCE
routines on memcpy() and help us make progress towards globally
enabling -fstrict-flex-arrays=3 [2].
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays [1]
Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [2]
Link: https://github.com/KSPP/linux/issues/78
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
drivers/gpu/drm/i915/gt/uc/guc_capture_fwif.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
Comments
On Tue, Jan 10, 2023 at 10:44:53AM -0600, Gustavo A. R. Silva wrote: > Zero-length arrays are deprecated[1] and we are moving towards > adopting C99 flexible-array members, instead. So, replace zero-length > arrays in a couple of structures (three, actually) with flex-array > members. > > This helps with the ongoing efforts to tighten the FORTIFY_SOURCE > routines on memcpy() and help us make progress towards globally > enabling -fstrict-flex-arrays=3 [2]. > > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays [1] > Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [2] > Link: https://github.com/KSPP/linux/issues/78 > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> > --- > drivers/gpu/drm/i915/gt/uc/guc_capture_fwif.h | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/gpu/drm/i915/gt/uc/guc_capture_fwif.h b/drivers/gpu/drm/i915/gt/uc/guc_capture_fwif.h > index 3624abfd22d1..9d589c28f40f 100644 > --- a/drivers/gpu/drm/i915/gt/uc/guc_capture_fwif.h > +++ b/drivers/gpu/drm/i915/gt/uc/guc_capture_fwif.h > @@ -73,7 +73,7 @@ struct guc_debug_capture_list_header { > > struct guc_debug_capture_list { > struct guc_debug_capture_list_header header; > - struct guc_mmio_reg regs[0]; > + struct guc_mmio_reg regs[]; > } __packed; > > /** > @@ -125,7 +125,7 @@ struct guc_state_capture_header_t { > > struct guc_state_capture_t { > struct guc_state_capture_header_t header; > - struct guc_mmio_reg mmio_entries[0]; > + struct guc_mmio_reg mmio_entries[]; > } __packed; > > enum guc_capture_group_types { > @@ -145,7 +145,7 @@ struct guc_state_capture_group_header_t { > /* this is the top level structure where an error-capture dump starts */ > struct guc_state_capture_group_t { > struct guc_state_capture_group_header_t grp_header; > - struct guc_state_capture_t capture_entries[0]; > + struct guc_state_capture_t capture_entries[]; Please notice we are currently using sizeof(struct ...). Along with your proposed changes, shouldn't we also start using the struct_size() which already take the flexible array into account? > } __packed; > > /** > -- > 2.34.1 >
On Tue, Jan 10, 2023 at 02:28:11PM -0500, Rodrigo Vivi wrote: > > On Tue, Jan 10, 2023 at 10:44:53AM -0600, Gustavo A. R. Silva wrote: > > Zero-length arrays are deprecated[1] and we are moving towards > > adopting C99 flexible-array members, instead. So, replace zero-length > > arrays in a couple of structures (three, actually) with flex-array > > members. > > > > This helps with the ongoing efforts to tighten the FORTIFY_SOURCE > > routines on memcpy() and help us make progress towards globally > > enabling -fstrict-flex-arrays=3 [2]. > > > > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays [1] > > Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [2] > > Link: https://github.com/KSPP/linux/issues/78 > > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> > > > --- > > drivers/gpu/drm/i915/gt/uc/guc_capture_fwif.h | 6 +++--- > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/gpu/drm/i915/gt/uc/guc_capture_fwif.h b/drivers/gpu/drm/i915/gt/uc/guc_capture_fwif.h > > index 3624abfd22d1..9d589c28f40f 100644 > > --- a/drivers/gpu/drm/i915/gt/uc/guc_capture_fwif.h > > +++ b/drivers/gpu/drm/i915/gt/uc/guc_capture_fwif.h > > @@ -73,7 +73,7 @@ struct guc_debug_capture_list_header { > > > > struct guc_debug_capture_list { > > struct guc_debug_capture_list_header header; > > - struct guc_mmio_reg regs[0]; > > + struct guc_mmio_reg regs[]; > > } __packed; > > > > /** > > @@ -125,7 +125,7 @@ struct guc_state_capture_header_t { > > > > struct guc_state_capture_t { > > struct guc_state_capture_header_t header; > > - struct guc_mmio_reg mmio_entries[0]; > > + struct guc_mmio_reg mmio_entries[]; > > } __packed; > > > > enum guc_capture_group_types { > > @@ -145,7 +145,7 @@ struct guc_state_capture_group_header_t { > > /* this is the top level structure where an error-capture dump starts */ > > struct guc_state_capture_group_t { > > struct guc_state_capture_group_header_t grp_header; > > - struct guc_state_capture_t capture_entries[0]; > > + struct guc_state_capture_t capture_entries[]; > > Please notice we are currently using sizeof(struct ...). Yep; I noticed that. :) > Along with your proposed changes, shouldn't we also start using > the struct_size() which already take the flexible array into account? Not necessarily. In recent times, we don't include the struct_size changes in the same patch as the flex-array transformation. That's usually a follow-up patch. -- Gustavo
On Tue, Jan 10, 2023 at 01:42:57PM -0600, Gustavo A. R. Silva wrote: > On Tue, Jan 10, 2023 at 02:28:11PM -0500, Rodrigo Vivi wrote: > > > > On Tue, Jan 10, 2023 at 10:44:53AM -0600, Gustavo A. R. Silva wrote: > > > Zero-length arrays are deprecated[1] and we are moving towards > > > adopting C99 flexible-array members, instead. So, replace zero-length > > > arrays in a couple of structures (three, actually) with flex-array > > > members. > > > > > > This helps with the ongoing efforts to tighten the FORTIFY_SOURCE > > > routines on memcpy() and help us make progress towards globally > > > enabling -fstrict-flex-arrays=3 [2]. > > > > > > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays [1] > > > Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [2] > > > Link: https://github.com/KSPP/linux/issues/78 > > > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> > > > > > --- > > > drivers/gpu/drm/i915/gt/uc/guc_capture_fwif.h | 6 +++--- > > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > > > diff --git a/drivers/gpu/drm/i915/gt/uc/guc_capture_fwif.h b/drivers/gpu/drm/i915/gt/uc/guc_capture_fwif.h > > > index 3624abfd22d1..9d589c28f40f 100644 > > > --- a/drivers/gpu/drm/i915/gt/uc/guc_capture_fwif.h > > > +++ b/drivers/gpu/drm/i915/gt/uc/guc_capture_fwif.h > > > @@ -73,7 +73,7 @@ struct guc_debug_capture_list_header { > > > > > > struct guc_debug_capture_list { > > > struct guc_debug_capture_list_header header; > > > - struct guc_mmio_reg regs[0]; > > > + struct guc_mmio_reg regs[]; > > > } __packed; > > > > > > /** > > > @@ -125,7 +125,7 @@ struct guc_state_capture_header_t { > > > > > > struct guc_state_capture_t { > > > struct guc_state_capture_header_t header; > > > - struct guc_mmio_reg mmio_entries[0]; > > > + struct guc_mmio_reg mmio_entries[]; > > > } __packed; > > > > > > enum guc_capture_group_types { > > > @@ -145,7 +145,7 @@ struct guc_state_capture_group_header_t { > > > /* this is the top level structure where an error-capture dump starts */ > > > struct guc_state_capture_group_t { > > > struct guc_state_capture_group_header_t grp_header; > > > - struct guc_state_capture_t capture_entries[0]; > > > + struct guc_state_capture_t capture_entries[]; > > > > Please notice we are currently using sizeof(struct ...). > > Yep; I noticed that. :) > > > Along with your proposed changes, shouldn't we also start using > > the struct_size() which already take the flexible array into account? > > Not necessarily. In recent times, we don't include the struct_size > changes in the same patch as the flex-array transformation. That's > usually a follow-up patch. okay, if that's not a problem, let's go with this for now and wait for the follow ups. Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com> (and pushing it right now. Thanks for the patch) > > -- > Gustavo
diff --git a/drivers/gpu/drm/i915/gt/uc/guc_capture_fwif.h b/drivers/gpu/drm/i915/gt/uc/guc_capture_fwif.h index 3624abfd22d1..9d589c28f40f 100644 --- a/drivers/gpu/drm/i915/gt/uc/guc_capture_fwif.h +++ b/drivers/gpu/drm/i915/gt/uc/guc_capture_fwif.h @@ -73,7 +73,7 @@ struct guc_debug_capture_list_header { struct guc_debug_capture_list { struct guc_debug_capture_list_header header; - struct guc_mmio_reg regs[0]; + struct guc_mmio_reg regs[]; } __packed; /** @@ -125,7 +125,7 @@ struct guc_state_capture_header_t { struct guc_state_capture_t { struct guc_state_capture_header_t header; - struct guc_mmio_reg mmio_entries[0]; + struct guc_mmio_reg mmio_entries[]; } __packed; enum guc_capture_group_types { @@ -145,7 +145,7 @@ struct guc_state_capture_group_header_t { /* this is the top level structure where an error-capture dump starts */ struct guc_state_capture_group_t { struct guc_state_capture_group_header_t grp_header; - struct guc_state_capture_t capture_entries[0]; + struct guc_state_capture_t capture_entries[]; } __packed; /**