summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHalil Pasic <pasic@linux.ibm.com>2025-02-17 11:06:14 +0100
committerVasily Gorbik <gor@linux.ibm.com>2025-02-18 18:53:47 +0100
commitfd0c8b337579bd6720af4e07b2de3a01f58c608c (patch)
tree843ce619ad86320a360e2e7abb5f74e5d8b5e02f
parent92d03904b26d330b9a20f3abaa9cb78e6aba2265 (diff)
s390/vfio-ccw: Make mdev_types not look like a fake flex array
The vfio-ccw driver and the vfio parent device provided by it (parent) support just a single mdev_type, and this is not likely to change any time soon. To match the mdev interfaces nicely initially the choice was made that mdev_types (which gets passed into mdev_register_parent()) shall be an array of pointers to struct mdev_type with a single element, and to make things worse it ended up being the last member. Now the problem with that is that before C99 the usual way to get something similar to a flexible array member was to use a trailing array of size 0 or 1. This is what I called fake flex array. For a while now the community is trying to get rid of fake flex arrays. And while mdev_types was not a fake flex array but an array of size one, because it can easily be and probably was mistaken for a fake flex array it got converted into a real C99 flex array with a compile time known constant size of one. As per [1] it was established that "only fake flexible arrays should be transformed into C99 flex-array members". Since IMHO the entire point of flex arrays is being flexible about the array size at run time, a C99 flex array is a poor fit for mdev_types. But an array of a size one is a poor fit as well for the reason stated above, let us try to get rid of the flex array without introducing back the one sized array. So, lets make mdev_types a pointer to struct mdev_type and pass in the address of that pointer as the 4th formal parameter of mdev_register_parent(). [1] https://lore.kernel.org/lkml/85863d7a-2d8b-4c1b-b76a-e2f40834a7a8@embeddedor.com/ Signed-off-by: Halil Pasic <pasic@linux.ibm.com> Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com> Tested-by: Eric Farman <farman@linux.ibm.com> Link: https://lore.kernel.org/r/20250217100614.3043620-3-pasic@linux.ibm.com Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
-rw-r--r--drivers/s390/cio/vfio_ccw_drv.c6
-rw-r--r--drivers/s390/cio/vfio_ccw_private.h2
2 files changed, 4 insertions, 4 deletions
diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c
index 914dde041675..6ff5c9cfb7ed 100644
--- a/drivers/s390/cio/vfio_ccw_drv.c
+++ b/drivers/s390/cio/vfio_ccw_drv.c
@@ -171,7 +171,7 @@ static int vfio_ccw_sch_probe(struct subchannel *sch)
return -ENODEV;
}
- parent = kzalloc(struct_size(parent, mdev_types, 1), GFP_KERNEL);
+ parent = kzalloc(sizeof(*parent), GFP_KERNEL);
if (!parent)
return -ENOMEM;
@@ -186,10 +186,10 @@ static int vfio_ccw_sch_probe(struct subchannel *sch)
parent->mdev_type.sysfs_name = "io";
parent->mdev_type.pretty_name = "I/O subchannel (Non-QDIO)";
- parent->mdev_types[0] = &parent->mdev_type;
+ parent->mdev_types = &parent->mdev_type;
ret = mdev_register_parent(&parent->parent, &sch->dev,
&vfio_ccw_mdev_driver,
- parent->mdev_types, 1);
+ &parent->mdev_types, 1);
if (ret)
goto out_unreg;
diff --git a/drivers/s390/cio/vfio_ccw_private.h b/drivers/s390/cio/vfio_ccw_private.h
index b62bbc5c6376..0501d4bbcdbd 100644
--- a/drivers/s390/cio/vfio_ccw_private.h
+++ b/drivers/s390/cio/vfio_ccw_private.h
@@ -79,7 +79,7 @@ struct vfio_ccw_parent {
struct mdev_parent parent;
struct mdev_type mdev_type;
- struct mdev_type *mdev_types[];
+ struct mdev_type *mdev_types;
};
/**