Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: Lijo Lazar <lijo.lazar@amd.com>
Reviewed-by: Hawking Zhang <Hawking.Zhang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Lijo Lazar and committed by
Alex Deucher
896ffa98 d31ed58e

+16 -17
+11 -10
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
··· 1984 1984 1985 1985 int amdgpu_discovery_get_nps_info(struct amdgpu_device *adev, 1986 1986 uint32_t *nps_type, 1987 - struct amdgpu_gmc_memrange **ranges, 1987 + struct amdgpu_gmc_memrange *ranges, 1988 1988 int *range_cnt, bool refresh) 1989 1989 { 1990 1990 uint8_t *discovery_bin = adev->discovery.bin; 1991 - struct amdgpu_gmc_memrange *mem_ranges; 1992 1991 struct table_info *info; 1993 1992 union nps_info *nps_info; 1994 1993 union nps_info nps_data; ··· 2025 2026 2026 2027 switch (le16_to_cpu(nps_info->v1.header.version_major)) { 2027 2028 case 1: 2028 - mem_ranges = kvzalloc_objs(*mem_ranges, nps_info->v1.count); 2029 - if (!mem_ranges) 2030 - return -ENOMEM; 2031 2029 *nps_type = nps_info->v1.nps_type; 2030 + if (*range_cnt < nps_info->v1.count) { 2031 + dev_dbg(adev->dev, 2032 + "not enough space for nps ranges: %d < %d\n", 2033 + *range_cnt, nps_info->v1.count); 2034 + return -ENOSPC; 2035 + } 2032 2036 *range_cnt = nps_info->v1.count; 2033 2037 for (i = 0; i < *range_cnt; i++) { 2034 - mem_ranges[i].base_address = 2038 + ranges[i].base_address = 2035 2039 nps_info->v1.instance_info[i].base_address; 2036 - mem_ranges[i].limit_address = 2040 + ranges[i].limit_address = 2037 2041 nps_info->v1.instance_info[i].limit_address; 2038 - mem_ranges[i].nid_mask = -1; 2039 - mem_ranges[i].flags = 0; 2042 + ranges[i].nid_mask = -1; 2043 + ranges[i].flags = 0; 2040 2044 } 2041 - *ranges = mem_ranges; 2042 2045 break; 2043 2046 default: 2044 2047 dev_err(adev->dev, "Unhandled NPS info table %d.%d\n",
+1 -1
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h
··· 46 46 47 47 int amdgpu_discovery_get_nps_info(struct amdgpu_device *adev, 48 48 uint32_t *nps_type, 49 - struct amdgpu_gmc_memrange **ranges, 49 + struct amdgpu_gmc_memrange *ranges, 50 50 int *range_cnt, bool refresh); 51 51 52 52 void amdgpu_discovery_dump(struct amdgpu_device *adev, struct drm_printer *p);
+4 -6
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
··· 1374 1374 struct amdgpu_mem_partition_info *mem_ranges, 1375 1375 uint8_t *exp_ranges) 1376 1376 { 1377 - struct amdgpu_gmc_memrange *ranges; 1377 + struct amdgpu_gmc_memrange ranges[AMDGPU_MAX_MEM_RANGES]; 1378 1378 int range_cnt, ret, i, j; 1379 1379 uint32_t nps_type; 1380 1380 bool refresh; 1381 1381 1382 1382 if (!mem_ranges || !exp_ranges) 1383 1383 return -EINVAL; 1384 - 1384 + range_cnt = AMDGPU_MAX_MEM_RANGES; 1385 1385 refresh = (adev->init_lvl->level != AMDGPU_INIT_LEVEL_MINIMAL_XGMI) && 1386 1386 (adev->gmc.reset_flags & AMDGPU_GMC_INIT_RESET_NPS); 1387 - ret = amdgpu_discovery_get_nps_info(adev, &nps_type, &ranges, 1388 - &range_cnt, refresh); 1387 + ret = amdgpu_discovery_get_nps_info(adev, &nps_type, ranges, &range_cnt, 1388 + refresh); 1389 1389 1390 1390 if (ret) 1391 1391 return ret; ··· 1446 1446 if (!*exp_ranges) 1447 1447 *exp_ranges = range_cnt; 1448 1448 err: 1449 - kvfree(ranges); 1450 - 1451 1449 return ret; 1452 1450 } 1453 1451