* [PATCH] drm/radeon: Avoid open coded arithmetic in memory allocation
@ 2022-02-05 17:38 Christophe JAILLET
2022-02-07 8:01 ` Christian König
0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2022-02-05 17:38 UTC (permalink / raw)
To: Alex Deucher, Christian König, Pan, Xinhui, David Airlie,
Daniel Vetter
Cc: Christophe JAILLET, dri-devel, kernel-janitors, linux-kernel, amd-gfx
kmalloc_array()/kcalloc() should be used to avoid potential overflow when
a multiplication is needed to compute the size of the requested memory.
So turn a kzalloc()+explicit size computation into an equivalent kcalloc().
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
drivers/gpu/drm/radeon/radeon_atombios.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c b/drivers/gpu/drm/radeon/radeon_atombios.c
index 28c4413f4dc8..7b9cc7a9f42f 100644
--- a/drivers/gpu/drm/radeon/radeon_atombios.c
+++ b/drivers/gpu/drm/radeon/radeon_atombios.c
@@ -897,13 +897,13 @@ bool radeon_get_atom_connector_info_from_supported_devices_table(struct
union atom_supported_devices *supported_devices;
int i, j, max_device;
struct bios_connector *bios_connectors;
- size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE;
struct radeon_router router;
router.ddc_valid = false;
router.cd_valid = false;
- bios_connectors = kzalloc(bc_size, GFP_KERNEL);
+ bios_connectors = kcalloc(ATOM_MAX_SUPPORTED_DEVICE,
+ sizeof(*bios_connectors), GFP_KERNEL);
if (!bios_connectors)
return false;
--
2.32.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] drm/radeon: Avoid open coded arithmetic in memory allocation
2022-02-05 17:38 [PATCH] drm/radeon: Avoid open coded arithmetic in memory allocation Christophe JAILLET
@ 2022-02-07 8:01 ` Christian König
0 siblings, 0 replies; 2+ messages in thread
From: Christian König @ 2022-02-07 8:01 UTC (permalink / raw)
To: Christophe JAILLET, Alex Deucher, Pan, Xinhui, David Airlie,
Daniel Vetter
Cc: dri-devel, kernel-janitors, linux-kernel, amd-gfx
Am 05.02.22 um 18:38 schrieb Christophe JAILLET:
> kmalloc_array()/kcalloc() should be used to avoid potential overflow when
> a multiplication is needed to compute the size of the requested memory.
>
> So turn a kzalloc()+explicit size computation into an equivalent kcalloc().
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Christian König <christian.koenig@amd.com>
> ---
> drivers/gpu/drm/radeon/radeon_atombios.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c b/drivers/gpu/drm/radeon/radeon_atombios.c
> index 28c4413f4dc8..7b9cc7a9f42f 100644
> --- a/drivers/gpu/drm/radeon/radeon_atombios.c
> +++ b/drivers/gpu/drm/radeon/radeon_atombios.c
> @@ -897,13 +897,13 @@ bool radeon_get_atom_connector_info_from_supported_devices_table(struct
> union atom_supported_devices *supported_devices;
> int i, j, max_device;
> struct bios_connector *bios_connectors;
> - size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE;
> struct radeon_router router;
>
> router.ddc_valid = false;
> router.cd_valid = false;
>
> - bios_connectors = kzalloc(bc_size, GFP_KERNEL);
> + bios_connectors = kcalloc(ATOM_MAX_SUPPORTED_DEVICE,
> + sizeof(*bios_connectors), GFP_KERNEL);
> if (!bios_connectors)
> return false;
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-02-07 8:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-05 17:38 [PATCH] drm/radeon: Avoid open coded arithmetic in memory allocation Christophe JAILLET
2022-02-07 8:01 ` Christian König
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).