Commit 130c7ed8 authored by Yunshui Jiang's avatar Yunshui Jiang Committed by Alex Deucher
Browse files

drm/amdgpu: use kmalloc_array() instead of kmalloc()



Use kmalloc_array() instead of kmalloc() with multiplication.
kmalloc_array() is a safer way because of its multiply overflow check.

Signed-off-by: default avatarYunshui Jiang <jiangyunshui@kylinos.cn>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 46b0e6b9
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -2622,7 +2622,7 @@ static int amdgpu_ras_badpages_read(struct amdgpu_device *adev,
		goto out;
	}

	*bps = kmalloc(sizeof(struct ras_badpage) * data->count, GFP_KERNEL);
	*bps = kmalloc_array(data->count, sizeof(struct ras_badpage), GFP_KERNEL);
	if (!*bps) {
		ret = -ENOMEM;
		goto out;
@@ -2786,7 +2786,7 @@ static int amdgpu_ras_realloc_eh_data_space(struct amdgpu_device *adev,
	unsigned int old_space = data->count + data->space_left;
	unsigned int new_space = old_space + pages;
	unsigned int align_space = ALIGN(new_space, 512);
	void *bps = kmalloc(align_space * sizeof(*data->bps), GFP_KERNEL);
	void *bps = kmalloc_array(align_space, sizeof(*data->bps), GFP_KERNEL);

	if (!bps) {
		return -ENOMEM;