* [PATCH] amd/amdgpu: use kmalloc_array to replace kmalloc with multiply
@ 2020-11-18 2:55 Bernard Zhao
2020-11-18 8:17 ` Christian König
0 siblings, 1 reply; 3+ messages in thread
From: Bernard Zhao @ 2020-11-18 2:55 UTC (permalink / raw)
To: Alex Deucher, Christian König, David Airlie, Daniel Vetter,
Monk Liu, Hawking Zhang, Yintian Tao, Dennis Li, Wenhui Sheng,
chen gong, Bokun Zhang, Stanley.Yang, amd-gfx, dri-devel,
linux-kernel
Cc: opensource.kernel, Bernard Zhao
Fix check_patch.pl warning:
WARNING: Prefer kmalloc_array over kmalloc with multiply
+bps = kmalloc(align_space * sizeof((*data)->bps), GFP_KERNEL);
WARNING: Prefer kmalloc_array over kmalloc with multiply
+bps_bo = kmalloc(align_space * sizeof((*data)->bps_bo),
GFP_KERNEL);
kmalloc_array has multiply overflow check, which will be safer.
Signed-off-by: Bernard Zhao <bernard@vivo.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
index d0aea5e39531..f2a0851c804f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
@@ -280,8 +280,8 @@ static int amdgpu_virt_init_ras_err_handler_data(struct amdgpu_device *adev)
if (!*data)
return -ENOMEM;
- bps = kmalloc(align_space * sizeof((*data)->bps), GFP_KERNEL);
- bps_bo = kmalloc(align_space * sizeof((*data)->bps_bo), GFP_KERNEL);
+ bps = kmalloc_array(align_space, sizeof((*data)->bps), GFP_KERNEL);
+ bps_bo = kmalloc_array(align_space, sizeof((*data)->bps_bo), GFP_KERNEL);
if (!bps || !bps_bo) {
kfree(bps);
--
2.29.0
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] amd/amdgpu: use kmalloc_array to replace kmalloc with multiply
2020-11-18 2:55 [PATCH] amd/amdgpu: use kmalloc_array to replace kmalloc with multiply Bernard Zhao
@ 2020-11-18 8:17 ` Christian König
2020-11-19 21:56 ` Alex Deucher
0 siblings, 1 reply; 3+ messages in thread
From: Christian König @ 2020-11-18 8:17 UTC (permalink / raw)
To: Bernard Zhao, Alex Deucher, David Airlie, Daniel Vetter,
Monk Liu, Hawking Zhang, Yintian Tao, Dennis Li, Wenhui Sheng,
chen gong, Bokun Zhang, Stanley.Yang, amd-gfx, dri-devel,
linux-kernel
Cc: opensource.kernel
Am 18.11.20 um 03:55 schrieb Bernard Zhao:
> Fix check_patch.pl warning:
> WARNING: Prefer kmalloc_array over kmalloc with multiply
> +bps = kmalloc(align_space * sizeof((*data)->bps), GFP_KERNEL);
> WARNING: Prefer kmalloc_array over kmalloc with multiply
> +bps_bo = kmalloc(align_space * sizeof((*data)->bps_bo),
> GFP_KERNEL);
> kmalloc_array has multiply overflow check, which will be safer.
>
> Signed-off-by: Bernard Zhao <bernard@vivo.com>
Not userspace controllable values, but looks cleaner anyway.
Reviewed-by: Christian König <christian.koenig@amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> index d0aea5e39531..f2a0851c804f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> @@ -280,8 +280,8 @@ static int amdgpu_virt_init_ras_err_handler_data(struct amdgpu_device *adev)
> if (!*data)
> return -ENOMEM;
>
> - bps = kmalloc(align_space * sizeof((*data)->bps), GFP_KERNEL);
> - bps_bo = kmalloc(align_space * sizeof((*data)->bps_bo), GFP_KERNEL);
> + bps = kmalloc_array(align_space, sizeof((*data)->bps), GFP_KERNEL);
> + bps_bo = kmalloc_array(align_space, sizeof((*data)->bps_bo), GFP_KERNEL);
>
> if (!bps || !bps_bo) {
> kfree(bps);
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] amd/amdgpu: use kmalloc_array to replace kmalloc with multiply
2020-11-18 8:17 ` Christian König
@ 2020-11-19 21:56 ` Alex Deucher
0 siblings, 0 replies; 3+ messages in thread
From: Alex Deucher @ 2020-11-19 21:56 UTC (permalink / raw)
To: Christian König
Cc: opensource.kernel, amd-gfx list, chen gong, David Airlie,
Bernard Zhao, Maling list - DRI developers, LKML, Wenhui Sheng,
Stanley.Yang, Dennis Li, Bokun Zhang, Alex Deucher, Yintian Tao,
Monk Liu, Hawking Zhang
Applied. Thanks!
Alex
On Wed, Nov 18, 2020 at 3:18 AM Christian König
<christian.koenig@amd.com> wrote:
>
> Am 18.11.20 um 03:55 schrieb Bernard Zhao:
> > Fix check_patch.pl warning:
> > WARNING: Prefer kmalloc_array over kmalloc with multiply
> > +bps = kmalloc(align_space * sizeof((*data)->bps), GFP_KERNEL);
> > WARNING: Prefer kmalloc_array over kmalloc with multiply
> > +bps_bo = kmalloc(align_space * sizeof((*data)->bps_bo),
> > GFP_KERNEL);
> > kmalloc_array has multiply overflow check, which will be safer.
> >
> > Signed-off-by: Bernard Zhao <bernard@vivo.com>
>
> Not userspace controllable values, but looks cleaner anyway.
>
> Reviewed-by: Christian König <christian.koenig@amd.com>
>
> > ---
> > drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> > index d0aea5e39531..f2a0851c804f 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> > @@ -280,8 +280,8 @@ static int amdgpu_virt_init_ras_err_handler_data(struct amdgpu_device *adev)
> > if (!*data)
> > return -ENOMEM;
> >
> > - bps = kmalloc(align_space * sizeof((*data)->bps), GFP_KERNEL);
> > - bps_bo = kmalloc(align_space * sizeof((*data)->bps_bo), GFP_KERNEL);
> > + bps = kmalloc_array(align_space, sizeof((*data)->bps), GFP_KERNEL);
> > + bps_bo = kmalloc_array(align_space, sizeof((*data)->bps_bo), GFP_KERNEL);
> >
> > if (!bps || !bps_bo) {
> > kfree(bps);
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-11-19 21:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-18 2:55 [PATCH] amd/amdgpu: use kmalloc_array to replace kmalloc with multiply Bernard Zhao
2020-11-18 8:17 ` Christian König
2020-11-19 21:56 ` Alex Deucher
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).