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

Gustavo A. R. Silva posted 2 patches 2 years, 8 months ago
[PATCH 2/2][next] vfio/ccw: Use struct_size() helper
Posted by Gustavo A. R. Silva 2 years, 8 months ago
Prefer struct_size() over open-coded versions.

Link: https://github.com/KSPP/linux/issues/160
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 drivers/s390/cio/vfio_ccw_drv.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c
index 57906a9c6324..43601816ea4e 100644
--- a/drivers/s390/cio/vfio_ccw_drv.c
+++ b/drivers/s390/cio/vfio_ccw_drv.c
@@ -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;
 
-- 
2.34.1
Re: [PATCH 2/2][next] vfio/ccw: Use struct_size() helper
Posted by Kees Cook 2 years, 8 months ago
On Mon, May 22, 2023 at 07:35:59PM -0600, Gustavo A. R. Silva wrote:
> Prefer struct_size() over open-coded versions.
> 
> Link: https://github.com/KSPP/linux/issues/160
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook
Re: [PATCH 2/2][next] vfio/ccw: Use struct_size() helper
Posted by Eric Farman 2 years, 8 months ago
On Mon, 2023-05-22 at 19:35 -0600, Gustavo A. R. Silva wrote:
> Prefer struct_size() over open-coded versions.
> 
> Link: https://github.com/KSPP/linux/issues/160
> 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 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/s390/cio/vfio_ccw_drv.c
> b/drivers/s390/cio/vfio_ccw_drv.c
> index 57906a9c6324..43601816ea4e 100644
> --- a/drivers/s390/cio/vfio_ccw_drv.c
> +++ b/drivers/s390/cio/vfio_ccw_drv.c
> @@ -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;
>