diff mbox series

[1/2,next] vfio/ccw: Replace one-element array with flexible-array member

Message ID 3c10549ebe1564eade68a2515bde233527376971.1684805398.git.gustavoars@kernel.org (mailing list archive)
State New, archived
Headers show
Series vfio/ccw: Replace one-element array with flexible-array member | expand

Commit Message

Gustavo A. R. Silva May 23, 2023, 1:35 a.m. UTC
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.

Link: https://github.com/KSPP/linux/issues/79
Link: https://github.com/KSPP/linux/issues/297
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 drivers/s390/cio/vfio_ccw_drv.c     | 3 ++-
 drivers/s390/cio/vfio_ccw_private.h | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

Comments

Eric Farman May 23, 2023, 4:33 p.m. UTC | #1
On Mon, 2023-05-22 at 19:35 -0600, Gustavo A. R. Silva wrote:
> 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/

> code
> accordingly.
> 
> Link: https://github.com/KSPP/linux/issues/79
> Link: https://github.com/KSPP/linux/issues/297
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Reviewed-by: Eric Farman <farman@linux.ibm.com>

> ---
>  drivers/s390/cio/vfio_ccw_drv.c     | 3 ++-
>  drivers/s390/cio/vfio_ccw_private.h | 2 +-
>  2 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/s390/cio/vfio_ccw_drv.c
> b/drivers/s390/cio/vfio_ccw_drv.c
> index ff538a086fc7..57906a9c6324 100644
> --- a/drivers/s390/cio/vfio_ccw_drv.c
> +++ b/drivers/s390/cio/vfio_ccw_drv.c
> @@ -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;
>  
> diff --git a/drivers/s390/cio/vfio_ccw_private.h
> b/drivers/s390/cio/vfio_ccw_private.h
> index b441ae6700fd..b62bbc5c6376 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[1];
> +       struct mdev_type        *mdev_types[];
>  };
>  
>  /**
Kees Cook May 23, 2023, 5:29 p.m. UTC | #2
On Mon, May 22, 2023 at 07:35:12PM -0600, Gustavo A. R. Silva wrote:
> 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.
> 
> Link: https://github.com/KSPP/linux/issues/79
> Link: https://github.com/KSPP/linux/issues/297
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Reviewed-by: Kees Cook <keescook@chromium.org>
Christophe JAILLET May 23, 2023, 5:45 p.m. UTC | #3
Le 23/05/2023 à 03:35, Gustavo A. R. Silva a écrit :
> 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.
> 
> Link: https://github.com/KSPP/linux/issues/79
> Link: https://github.com/KSPP/linux/issues/297
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
>   drivers/s390/cio/vfio_ccw_drv.c     | 3 ++-
>   drivers/s390/cio/vfio_ccw_private.h | 2 +-
>   2 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c
> index ff538a086fc7..57906a9c6324 100644
> --- a/drivers/s390/cio/vfio_ccw_drv.c
> +++ b/drivers/s390/cio/vfio_ccw_drv.c
> @@ -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

> +			 GFP_KERNEL);
>   	if (!parent)
>   		return -ENOMEM;
>   
> diff --git a/drivers/s390/cio/vfio_ccw_private.h b/drivers/s390/cio/vfio_ccw_private.h
> index b441ae6700fd..b62bbc5c6376 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[1];
> +	struct mdev_type	*mdev_types[];
>   };
>   
>   /**
Christophe JAILLET May 23, 2023, 5:47 p.m. UTC | #4
Le 23/05/2023 à 19:45, Christophe JAILLET a écrit :
> Le 23/05/2023 à 03:35, Gustavo A. R. Silva a écrit :
>> 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.
>>
>> Link: https://github.com/KSPP/linux/issues/79
>> Link: https://github.com/KSPP/linux/issues/297
>> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
>> ---
>>   drivers/s390/cio/vfio_ccw_drv.c     | 3 ++-
>>   drivers/s390/cio/vfio_ccw_private.h | 2 +-
>>   2 files changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/s390/cio/vfio_ccw_drv.c 
>> b/drivers/s390/cio/vfio_ccw_drv.c
>> index ff538a086fc7..57906a9c6324 100644
>> --- a/drivers/s390/cio/vfio_ccw_drv.c
>> +++ b/drivers/s390/cio/vfio_ccw_drv.c
>> @@ -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?

Ok, patch 2/2.

Sorry for the noise.

CJ

> 
> Just my 2c,
> 
> CJ
> 
>> +             GFP_KERNEL);
>>       if (!parent)
>>           return -ENOMEM;
>> diff --git a/drivers/s390/cio/vfio_ccw_private.h 
>> b/drivers/s390/cio/vfio_ccw_private.h
>> index b441ae6700fd..b62bbc5c6376 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[1];
>> +    struct mdev_type    *mdev_types[];
>>   };
>>   /**
> 
>
diff mbox series

Patch

diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c
index ff538a086fc7..57906a9c6324 100644
--- a/drivers/s390/cio/vfio_ccw_drv.c
+++ b/drivers/s390/cio/vfio_ccw_drv.c
@@ -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;
 
diff --git a/drivers/s390/cio/vfio_ccw_private.h b/drivers/s390/cio/vfio_ccw_private.h
index b441ae6700fd..b62bbc5c6376 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[1];
+	struct mdev_type	*mdev_types[];
 };
 
 /**