Commit 896ffa98 authored by Lijo Lazar's avatar Lijo Lazar Committed by Alex Deucher
Browse files

drm/amdgpu: Use stack variable to fetch nps info



Instead of a dynamic allocation, use stack variable and let the caller
pass the maximum ranges that can be held in the buffer.

Signed-off-by: default avatarLijo Lazar <lijo.lazar@amd.com>
Reviewed-by: default avatarHawking Zhang <Hawking.Zhang@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent d31ed58e
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -1984,11 +1984,10 @@ static int amdgpu_discovery_refresh_nps_info(struct amdgpu_device *adev,

int amdgpu_discovery_get_nps_info(struct amdgpu_device *adev,
				  uint32_t *nps_type,
				  struct amdgpu_gmc_memrange **ranges,
				  struct amdgpu_gmc_memrange *ranges,
				  int *range_cnt, bool refresh)
{
	uint8_t *discovery_bin = adev->discovery.bin;
	struct amdgpu_gmc_memrange *mem_ranges;
	struct table_info *info;
	union nps_info *nps_info;
	union nps_info nps_data;
@@ -2026,20 +2025,22 @@ int amdgpu_discovery_get_nps_info(struct amdgpu_device *adev,

	switch (le16_to_cpu(nps_info->v1.header.version_major)) {
	case 1:
		mem_ranges = kvzalloc_objs(*mem_ranges, nps_info->v1.count);
		if (!mem_ranges)
			return -ENOMEM;
		*nps_type = nps_info->v1.nps_type;
		if (*range_cnt < nps_info->v1.count) {
			dev_dbg(adev->dev,
				"not enough space for nps ranges: %d < %d\n",
				*range_cnt, nps_info->v1.count);
			return -ENOSPC;
		}
		*range_cnt = nps_info->v1.count;
		for (i = 0; i < *range_cnt; i++) {
			mem_ranges[i].base_address =
			ranges[i].base_address =
				nps_info->v1.instance_info[i].base_address;
			mem_ranges[i].limit_address =
			ranges[i].limit_address =
				nps_info->v1.instance_info[i].limit_address;
			mem_ranges[i].nid_mask = -1;
			mem_ranges[i].flags = 0;
			ranges[i].nid_mask = -1;
			ranges[i].flags = 0;
		}
		*ranges = mem_ranges;
		break;
	default:
		dev_err(adev->dev, "Unhandled NPS info table %d.%d\n",
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ int amdgpu_discovery_set_ip_blocks(struct amdgpu_device *adev);

int amdgpu_discovery_get_nps_info(struct amdgpu_device *adev,
				  uint32_t *nps_type,
				  struct amdgpu_gmc_memrange **ranges,
				  struct amdgpu_gmc_memrange *ranges,
				  int *range_cnt, bool refresh);

void amdgpu_discovery_dump(struct amdgpu_device *adev, struct drm_printer *p);
+4 −6
Original line number Diff line number Diff line
@@ -1374,18 +1374,18 @@ int amdgpu_gmc_get_nps_memranges(struct amdgpu_device *adev,
				 struct amdgpu_mem_partition_info *mem_ranges,
				 uint8_t *exp_ranges)
{
	struct amdgpu_gmc_memrange *ranges;
	struct amdgpu_gmc_memrange ranges[AMDGPU_MAX_MEM_RANGES];
	int range_cnt, ret, i, j;
	uint32_t nps_type;
	bool refresh;

	if (!mem_ranges || !exp_ranges)
		return -EINVAL;

	range_cnt = AMDGPU_MAX_MEM_RANGES;
	refresh = (adev->init_lvl->level != AMDGPU_INIT_LEVEL_MINIMAL_XGMI) &&
		  (adev->gmc.reset_flags & AMDGPU_GMC_INIT_RESET_NPS);
	ret = amdgpu_discovery_get_nps_info(adev, &nps_type, &ranges,
					    &range_cnt, refresh);
	ret = amdgpu_discovery_get_nps_info(adev, &nps_type, ranges, &range_cnt,
					    refresh);

	if (ret)
		return ret;
@@ -1446,8 +1446,6 @@ int amdgpu_gmc_get_nps_memranges(struct amdgpu_device *adev,
	if (!*exp_ranges)
		*exp_ranges = range_cnt;
err:
	kvfree(ranges);

	return ret;
}