drm/amdkfd: Use kvmalloc_array to allocate arrays
Subsystems (3)
PATCH 1/1 drm/amdkfd: Use kvmalloc_array to allocate arrays
There were a few instances in kfd_chardev.c of kvzalloc being used to allocate memory for an array.
Switch those to kvmalloc_array, which
- is the standard way of doing this
- does a check for the mul overflowing
Signed-off-by David Francis <[email protected]>
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +6 -6
@@ -1917,13 +1917,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 =kvmalloc_array (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 =kvmalloc_array (num_devices,sizeof (*device_priv),GFP_KERNEL );if (!device_priv) { ret = -ENOMEM ; goto exit;
@@ -2043,17 +2043,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 =kvmalloc_array (num_bos,sizeof (*bo_buckets),GFP_KERNEL );if (!bo_buckets)return -ENOMEM ; - bo_privs =kvzalloc (num_bos *sizeof (*bo_privs),GFP_KERNEL ); + bo_privs =kvmalloc_array (num_bos,sizeof (*bo_privs),GFP_KERNEL );if (!bo_privs) { ret = -ENOMEM ; goto exit; } - files =kvzalloc (num_bos *sizeof (struct file *),GFP_KERNEL ); + files =kvmalloc_array (num_bos,sizeof (struct file *),GFP_KERNEL );if (!files) { ret = -ENOMEM ; goto exit;
@@ -2584,7 +2584,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 =kvmalloc_array (args->num_bos,sizeof (struct file *),GFP_KERNEL );if (!files) { ret = -ENOMEM ; goto exit;
Signature · 1 line
2.34.1
Quoted 7 lines · David Francis
There were a few instances in
kfd_chardev.cof kvzalloc being used to allocate memory for an array.Switch those to
kvmalloc_array, which
- is the standard way of doing this
- does a check for the mul overflowing
I think kvcalloc() would be preferable as otherwise you lose the 0 init.
Alex
Quoted 59 lines
Signed-off-by David Francis <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +6
-7@@ -1917,13 +1917,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 =kvmalloc_array (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 =kvmalloc_array (num_devices,sizeof (*device_priv),GFP_KERNEL );if (!device_priv) { ret = -ENOMEM ; goto exit;@@ -2043,17 +2043,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 =kvmalloc_array (num_bos,sizeof (*bo_buckets),GFP_KERNEL );if (!bo_buckets)return -ENOMEM ; - bo_privs =kvzalloc (num_bos *sizeof (*bo_privs),GFP_KERNEL ); + bo_privs =kvmalloc_array (num_bos,sizeof (*bo_privs),GFP_KERNEL );if (!bo_privs) { ret = -ENOMEM ; goto exit; } - files =kvzalloc (num_bos *sizeof (struct file *),GFP_KERNEL ); + files =kvmalloc_array (num_bos,sizeof (struct file *),GFP_KERNEL );if (!files) { ret = -ENOMEM ; goto exit;@@ -2584,7 +2584,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 =kvmalloc_array (args->num_bos,sizeof (struct file *),GFP_KERNEL );if (!files) { ret = -ENOMEM ; goto exit; --2.34.1