diff mbox series

[next] drm/i915/guc: Replace zero-length arrays with flexible-array members

Message ID Y72WBTUmh9r1lvKN@work (mailing list archive)
State Mainlined
Commit f7a79bdc4e672092f111efc917668706c93b535f
Headers show
Series [next] drm/i915/guc: Replace zero-length arrays with flexible-array members | expand

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

Rodrigo Vivi Jan. 10, 2023, 7:28 p.m. UTC | #1
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
>
Gustavo A. R. Silva Jan. 10, 2023, 7:42 p.m. UTC | #2
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
Rodrigo Vivi Jan. 11, 2023, 9:16 a.m. UTC | #3
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 mbox series

Patch

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;
 
 /**