]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
s390/vfio-ap: Make mdev_types not look like a fake flex array
authorHalil Pasic <pasic@linux.ibm.com>
Mon, 17 Feb 2025 10:06:13 +0000 (11:06 +0100)
committerVasily Gorbik <gor@linux.ibm.com>
Tue, 18 Feb 2025 17:53:47 +0000 (18:53 +0100)
The vfio-ap driver and the vfio parent device provided by it
(matrix_dev) support just a single mdev_type, and this is not likely to
change any time soon.  Despite that matrix_dev->mdev_types started out
as a C99 flexible array presumably as a typo, and since the typo messed
up the allocation, commit e2c8cee9f489 ("s390/vfio-ap: Fix memory
allocation for mdev_types array") changed it to an array of size 1. And
to make things worse mdev_types happens to be the last member of struct
ap_matrix_dev.

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
is not a fake flex array but an array of size one (to match the mdev
interfaces nicer), it can easily be and was mistaken for a fake flex
array.

So, let us 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().

Signed-off-by: Halil Pasic <pasic@linux.ibm.com>
Reviewed-by: Anthony Krowiak <akrowiak@linux.ibm.com>
Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>
Reviewed-by: Eric Farman <farman@linux.ibm.com>
Tested-by: Anthony Krowiak <akrowiak@linux.ibm.com>
Link: https://lore.kernel.org/r/20250217100614.3043620-2-pasic@linux.ibm.com
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
drivers/s390/crypto/vfio_ap_ops.c
drivers/s390/crypto/vfio_ap_private.h

index 155e19aef5df9acac683d821fdc302dfdad7864f..4c6a6d91a13fa4439ec4ef535aa3dbcb8105074c 100644 (file)
@@ -2316,10 +2316,10 @@ int vfio_ap_mdev_register(void)
 
        matrix_dev->mdev_type.sysfs_name = VFIO_AP_MDEV_TYPE_HWVIRT;
        matrix_dev->mdev_type.pretty_name = VFIO_AP_MDEV_NAME_HWVIRT;
-       matrix_dev->mdev_types[0] = &matrix_dev->mdev_type;
+       matrix_dev->mdev_types = &matrix_dev->mdev_type;
        ret = mdev_register_parent(&matrix_dev->parent, &matrix_dev->device,
                                   &vfio_ap_matrix_driver,
-                                  matrix_dev->mdev_types, 1);
+                                  &matrix_dev->mdev_types, 1);
        if (ret)
                goto err_driver;
        return 0;
index 437a161c865983b353c319079f57f0fcaaf85757..9d16321777c8d4d47c9be420e98973cdb0764ec9 100644 (file)
@@ -53,7 +53,7 @@ struct ap_matrix_dev {
        struct mutex guests_lock; /* serializes access to each KVM guest */
        struct mdev_parent parent;
        struct mdev_type mdev_type;
-       struct mdev_type *mdev_types[1];
+       struct mdev_type *mdev_types;
 };
 
 extern struct ap_matrix_dev *matrix_dev;