vfio/ccw: Replace one-element array with flexible-array member
Subsystems (4)
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
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
@@ -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
@@ -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
PATCH 2/2 vfio/ccw: Use struct_size() helper
In reply to Gustavo A. R. SilvaPrefer 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
@@ -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
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 structvfio_ccw_parentand 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@@ -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@@ -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[];
};
/**
Re: [PATCH 2/2][next] vfio/ccw: Use struct_size() helper
In reply to Gustavo A. R. SilvaQuoted 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@@ -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;
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_SOURCEroutines onmemcpy()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: Usestruct_size()helperdrivers/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:
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_parentand refactor the the rest of the code accordingly.
Signature · 1 line
Kees Cook
Re: [PATCH 2/2][next] vfio/ccw: Use struct_size() helper
In reply to Gustavo A. R. SilvaQuoted 4 lines · Gustavo A. R. Silva
Prefer
struct_size()over open-coded versions.
Signature · 1 line
Kees Cook
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_parentand refactor the the rest of the code accordingly.Signed-off-by Gustavo A. R. Silva <[email protected]>--- 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
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@@ -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[]; };/**
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_parentand refactor the the rest of the code accordingly.Signed-off-by Gustavo A. R. Silva <[email protected]>---
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
-0drivers/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@@ -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[]; }; /**
Alexander Gordeev
maintainerQuoted 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_SOURCEroutines onmemcpy()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: Usestruct_size()helperdrivers/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!