]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/amdkfd: Use kvcalloc to allocate arrays
authorDavid Francis <David.Francis@amd.com>
Thu, 25 Jun 2026 14:09:13 +0000 (10:09 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 1 Jul 2026 17:01:50 +0000 (13:01 -0400)
There were a few instances in kfd_chardev.c of kvzalloc being
used to allocate memory for an array.

Switch those to kvcalloc, which
- is the standard way of allocating a zero-initialized array
- does a check for the mul overflowing

Signed-off-by: David Francis <David.Francis@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit 60b048c93f7a3add39757ad65fe2bb6e58eeae23)
Cc: stable@vger.kernel.org
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c

index 531e20748198c9e850b0ea1cf140d021323921fc..c7edebd2fd8a4ac07e22f94e8cc953110d05a1c4 100644 (file)
@@ -1914,13 +1914,13 @@ static int criu_checkpoint_devices(struct kfd_process *p,
        struct kfd_criu_device_bucket *device_buckets = NULL;
        int ret = 0, i;
 
-       device_buckets = kvzalloc(num_devices * sizeof(*device_buckets), GFP_KERNEL);
+       device_buckets = kvcalloc(num_devices, sizeof(*device_buckets), GFP_KERNEL);
        if (!device_buckets) {
                ret = -ENOMEM;
                goto exit;
        }
 
-       device_priv = kvzalloc(num_devices * sizeof(*device_priv), GFP_KERNEL);
+       device_priv = kvcalloc(num_devices, sizeof(*device_priv), GFP_KERNEL);
        if (!device_priv) {
                ret = -ENOMEM;
                goto exit;
@@ -2040,17 +2040,17 @@ static int criu_checkpoint_bos(struct kfd_process *p,
        int ret = 0, pdd_index, bo_index = 0, id;
        void *mem;
 
-       bo_buckets = kvzalloc(num_bos * sizeof(*bo_buckets), GFP_KERNEL);
+       bo_buckets = kvcalloc(num_bos, sizeof(*bo_buckets), GFP_KERNEL);
        if (!bo_buckets)
                return -ENOMEM;
 
-       bo_privs = kvzalloc(num_bos * sizeof(*bo_privs), GFP_KERNEL);
+       bo_privs = kvcalloc(num_bos, sizeof(*bo_privs), GFP_KERNEL);
        if (!bo_privs) {
                ret = -ENOMEM;
                goto exit;
        }
 
-       files = kvzalloc(num_bos * sizeof(struct file *), GFP_KERNEL);
+       files = kvcalloc(num_bos, sizeof(struct file *), GFP_KERNEL);
        if (!files) {
                ret = -ENOMEM;
                goto exit;
@@ -2581,7 +2581,7 @@ static int criu_restore_bos(struct kfd_process *p,
        if (!bo_buckets)
                return -ENOMEM;
 
-       files = kvzalloc(args->num_bos * sizeof(struct file *), GFP_KERNEL);
+       files = kvcalloc(args->num_bos, sizeof(struct file *), GFP_KERNEL);
        if (!files) {
                ret = -ENOMEM;
                goto exit;