Skip to contentSkip to conversation

vfio/ccw: Replace one-element array with flexible-array member

PATCH In review Gustavo A. R. Silva 6 participants 11 messages May 23, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover vfio/ccw: Replace one-element array with flexible-array member

Hi!

This small series aims to replace a one-element array with a flexible-array member in struct vfio_ccw_parent.

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 [1].

Gustavo A. R. Silva (2):
vfio/ccw: Replace one-element array with flexible-array member vfio/ccw: Use struct_size() helper

 drivers/s390/cio/vfio_ccw_drv.c     | 2 +-
 drivers/s390/cio/vfio_ccw_private.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 vfio/ccw: Replace one-element array with flexible-array member

One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element array with flexible-array member in struct vfio_ccw_parent and refactor the the rest of the code accordingly.

---
 drivers/s390/cio/vfio_ccw_drv.c     | 3 ++-
 drivers/s390/cio/vfio_ccw_private.h | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/s390/cio/vfio_ccw_drv.c +2 -1
index ff538a086fc7..57906a9c6324 100644
@@ -171,7 +171,8 @@ static int vfio_ccw_sch_probe(struct subchannel *sch)
 		return -ENODEV;
 	}
 
-	parent = kzalloc(sizeof(*parent), GFP_KERNEL);
+	parent = kzalloc(sizeof(*parent) + sizeof(struct mdev_type *),
+			 GFP_KERNEL);
 	if (!parent)
 		return -ENOMEM;
 
drivers/s390/cio/vfio_ccw_private.h +1 -1
index b441ae6700fd..b62bbc5c6376 100644
@@ -79,7 +79,7 @@ struct vfio_ccw_parent {
 
 	struct mdev_parent	parent;
 	struct mdev_type	mdev_type;
-	struct mdev_type	*mdev_types[1];
+	struct mdev_type	*mdev_types[];
 };
 
 /**
Signature · 1 line
2.34.1
#6 lore raw

PATCH 2/2 vfio/ccw: Use struct_size() helper

In reply to Gustavo A. R. Silva

Prefer struct_size() over open-coded versions.

---
 drivers/s390/cio/vfio_ccw_drv.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/s390/cio/vfio_ccw_drv.c +1 -2
index 57906a9c6324..43601816ea4e 100644
@@ -171,8 +171,7 @@ static int vfio_ccw_sch_probe(struct subchannel *sch)
 		return -ENODEV;
 	}
 
-	parent = kzalloc(sizeof(*parent) + sizeof(struct mdev_type *),
-			 GFP_KERNEL);
+	parent = kzalloc(struct_size(parent, mdev_types, 1), GFP_KERNEL);
 	if (!parent)
 		return -ENOMEM;
 
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/2
#2 lore raw
In reply to Gustavo A. R. Silva
Quoted 5 lines · Gustavo A. R. Silva

One-element arrays are deprecated, and we are replacing them with flexible
array members instead. So, replace one-element array with flexible- array
member in struct vfio_ccw_parent and refactor the the rest of the

s/the the/the/

Quoted 6 lines

code
accordingly.

Quoted 36 lines

---
 drivers/s390/cio/vfio_ccw_drv.c     | 3 ++-
 drivers/s390/cio/vfio_ccw_private.h | 2 +-

 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/s390/cio/vfio_ccw_drv.c +0 -0
index ff538a086fc7..57906a9c6324 100644
@@ -171,7 +171,8 @@ static int vfio_ccw_sch_probe(struct subchannel
 *sch)
                 return -ENODEV;
         }


-       parent = kzalloc(sizeof(*parent), GFP_KERNEL); +       parent = kzalloc(sizeof(*parent) + sizeof(struct mdev_type *),
+                        GFP_KERNEL);
        if (!parent)
                return -ENOMEM;

drivers/s390/cio/vfio_ccw_private.h +0 -0
index b441ae6700fd..b62bbc5c6376 100644
@@ -79,7 +79,7 @@ struct vfio_ccw_parent {


        struct mdev_parent      parent;
        struct mdev_type        mdev_type;
-       struct mdev_type        *mdev_types[1];
+       struct mdev_type        *mdev_types[];
 };

 /**

maintainer Reviewed-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2][next] vfio/ccw: Use struct_size() helper

In reply to Gustavo A. R. Silva
Quoted 4 lines · Gustavo A. R. Silva

Prefer struct_size() over open-coded versions.

Quoted 22 lines

---
 drivers/s390/cio/vfio_ccw_drv.c | 3 +--

 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/s390/cio/vfio_ccw_drv.c +0 -0
index 57906a9c6324..43601816ea4e 100644
@@ -171,8 +171,7 @@ static int vfio_ccw_sch_probe(struct subchannel
 *sch)
                 return -ENODEV;
         }


-       parent = kzalloc(sizeof(*parent) + sizeof(struct mdev_type *),
-                        GFP_KERNEL);
+       parent = kzalloc(struct_size(parent, mdev_types, 1), GFP_KERNEL);
        if (!parent)
                return -ENOMEM;

maintainer Reviewed-by on the v1 series
#9 lore raw
In reply to Gustavo A. R. Silva
Quoted 14 lines · Gustavo A. R. Silva

Hi!

This small series aims to replace a one-element array with a flexible-array member in struct vfio_ccw_parent.

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 [1].

Quoted 8 lines

Gustavo A. R. Silva (2):
vfio/ccw: Replace one-element array with flexible-array member vfio/ccw: Use struct_size() helper

 drivers/s390/cio/vfio_ccw_drv.c     | 2 +-
 drivers/s390/cio/vfio_ccw_private.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Hi Gustavo,

Thanks! For the series:

Reviewed-by on v1 1/2
#3 lore raw
In reply to Gustavo A. R. Silva
Quoted 8 lines · Gustavo A. R. Silva

One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element array with flexible-array member in struct vfio_ccw_parent and refactor the the rest of the code accordingly.

Signature · 1 line
Kees Cook
#4 lore raw
In reply to Gustavo A. R. Silva

Le 23/05/2023 à 03:35, Gustavo A. R. Silva a écrit :

Quoted 18 lines

One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element array with flexible-array member in struct vfio_ccw_parent and refactor the the rest of the code accordingly.

---
  drivers/s390/cio/vfio_ccw_drv.c     | 3 ++-
  drivers/s390/cio/vfio_ccw_private.h | 2 +-
  2 files changed, 3 insertions(+), 2 deletions(-)
drivers/s390/cio/vfio_ccw_drv.c +0 -0
index ff538a086fc7..57906a9c6324 100644

drivers/s390/cio/vfio_ccw_drv.c static int vfio_ccw_sch_probe(struct subchannel *sch) · line 174

Quoted 5 lines
drivers/s390/cio/vfio_ccw_drv.c +1 -1
@@ -171,7 +171,8 @@ static int vfio_ccw_sch_probe(struct subchannel *sch)
  		return -ENODEV;
  	}
 
-	parent = kzalloc(sizeof(*parent), GFP_KERNEL);
+	parent = kzalloc(sizeof(*parent) + sizeof(struct mdev_type *),

Hi, wouldn't:

parent = kzalloc(struct_size(parent, mdev_types, 1)),

be more informative and in the spirit of flexible array use?

Just my 2c,

CJ

Quoted 17 lines
drivers/s390/cio/vfio_ccw_drv.c +1 -0
+			 GFP_KERNEL);
  	if (!parent)
  		return -ENOMEM;
 
drivers/s390/cio/vfio_ccw_private.h +1 -1
index b441ae6700fd..b62bbc5c6376 100644
@@ -79,7 +79,7 @@ struct vfio_ccw_parent {
 
  	struct mdev_parent	parent;
  	struct mdev_type	mdev_type;
-	struct mdev_type	*mdev_types[1];
+	struct mdev_type	*mdev_types[];
  };
 
  /**
#5 lore raw

Le 23/05/2023 à 19:45, Christophe JAILLET a écrit :

Quoted 26 lines

Le 23/05/2023 à 03:35, Gustavo A. R. Silva a écrit :

Quoted 18 lines

One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element array with flexible-array member in struct vfio_ccw_parent and refactor the the rest of the code accordingly.

---
  drivers/s390/cio/vfio_ccw_drv.c     | 3 ++-
  drivers/s390/cio/vfio_ccw_private.h | 2 +-

  2 files changed, 3 insertions(+), 2 deletions(-)
drivers/s390/cio/vfio_ccw_drv.c +0 -0
index ff538a086fc7..57906a9c6324 100644

drivers/s390/cio/vfio_ccw_drv.c static int vfio_ccw_sch_probe(struct subchannel *sch) · line 173

Quoted 4 lines
drivers/s390/cio/vfio_ccw_drv.c +1 -1
@@ -171,7 +171,8 @@ static int vfio_ccw_sch_probe(struct subchannel *sch)
           return -ENODEV;
       }
-    parent = kzalloc(sizeof(*parent), GFP_KERNEL);
+    parent = kzalloc(sizeof(*parent) + sizeof(struct mdev_type *),

Hi, wouldn't:

Quoted 3 lines

   parent = kzalloc(struct_size(parent, mdev_types, 1)),

be more informative and in the spirit of flexible array use?

Ok, patch 2/2.

Sorry for the noise.

CJ

Quoted 21 lines

Just my 2c,

CJ

Quoted 14 lines
drivers/s390/cio/vfio_ccw_drv.c +1 -0
+             GFP_KERNEL);
       if (!parent)
           return -ENOMEM;
drivers/s390/cio/vfio_ccw_private.h +1 -1
index b441ae6700fd..b62bbc5c6376 100644
@@ -79,7 +79,7 @@ struct vfio_ccw_parent {
       struct mdev_parent    parent;
       struct mdev_type    mdev_type;
-    struct mdev_type    *mdev_types[1];
+    struct mdev_type    *mdev_types[];
   };
   /**
#10 lore raw
In reply to Gustavo A. R. Silva
Quoted 12 lines · Gustavo A. R. Silva

This small series aims to replace a one-element array with a flexible-array member in struct vfio_ccw_parent.

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 [1].

Quoted 7 lines

Gustavo A. R. Silva (2):
vfio/ccw: Replace one-element array with flexible-array member vfio/ccw: Use struct_size() helper

 drivers/s390/cio/vfio_ccw_drv.c     | 2 +-
 drivers/s390/cio/vfio_ccw_private.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Fixed duplicate "the the" in patch #1 commit message and applied.

Thanks!