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

drm/amdgpu: Use flexible array member

Use flexible array member in ip discovery struct as recommended[1].

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

v2: squash in struct_size fixes

Signed-off-by: Lijo Lazar <lijo.lazar@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Lijo Lazar and committed by
Alex Deucher
73bce7a4 25faeddc

+5 -5
+4 -4
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
··· 430 430 } 431 431 } 432 432 next_ip: 433 - ip_offset += sizeof(*ip) + 4 * (ip->num_base_address - 1); 433 + ip_offset += struct_size(ip, base_address, ip->num_base_address); 434 434 } 435 435 } 436 436 } ··· 798 798 res = kobject_add(&ip_hw_instance->kobj, NULL, 799 799 "%d", ip_hw_instance->num_instance); 800 800 next_ip: 801 - ip_offset += sizeof(*ip) + 4 * (ip->num_base_address - 1); 801 + ip_offset += struct_size(ip, base_address, ip->num_base_address); 802 802 } 803 803 } 804 804 ··· 1063 1063 } 1064 1064 1065 1065 next_ip: 1066 - ip_offset += sizeof(*ip) + 4 * (ip->num_base_address - 1); 1066 + ip_offset += struct_size(ip, base_address, ip->num_base_address); 1067 1067 } 1068 1068 } 1069 1069 ··· 1113 1113 *revision = ip->revision; 1114 1114 return 0; 1115 1115 } 1116 - ip_offset += sizeof(*ip) + 4 * (ip->num_base_address - 1); 1116 + ip_offset += struct_size(ip, base_address, ip->num_base_address); 1117 1117 } 1118 1118 } 1119 1119
+1 -1
drivers/gpu/drm/amd/include/discovery.h
··· 93 93 uint8_t harvest : 4; /* Harvest */ 94 94 uint8_t reserved : 4; /* Placeholder field */ 95 95 #endif 96 - uint32_t base_address[1]; /* variable number of Addresses */ 96 + uint32_t base_address[]; /* variable number of Addresses */ 97 97 } ip; 98 98 99 99 typedef struct die_header