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

drm/amdgpu: check function points valid before use. (v3)

v2: agd: integrate Christian's comments.
v3: print error message if call fails

Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Rex Zhu <Rex.Zhu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Rex Zhu and committed by
Alex Deucher
c722865a 5463545b

+18 -14
+18 -14
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
··· 1191 1191 for (i = 0; i < adev->num_ip_blocks; i++) { 1192 1192 if (!adev->ip_blocks[i].status.valid) 1193 1193 continue; 1194 - if (adev->ip_blocks[i].version->type == block_type) { 1195 - r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev, 1196 - state); 1197 - if (r) 1198 - return r; 1199 - break; 1200 - } 1194 + if (adev->ip_blocks[i].version->type != block_type) 1195 + continue; 1196 + if (!adev->ip_blocks[i].version->funcs->set_clockgating_state) 1197 + continue; 1198 + r = adev->ip_blocks[i].version->funcs->set_clockgating_state( 1199 + (void *)adev, state); 1200 + if (r) 1201 + DRM_ERROR("set_clockgating_state of IP block <%s> failed %d\n", 1202 + adev->ip_blocks[i].version->funcs->name, r); 1201 1203 } 1202 1204 return r; 1203 1205 } ··· 1213 1211 for (i = 0; i < adev->num_ip_blocks; i++) { 1214 1212 if (!adev->ip_blocks[i].status.valid) 1215 1213 continue; 1216 - if (adev->ip_blocks[i].version->type == block_type) { 1217 - r = adev->ip_blocks[i].version->funcs->set_powergating_state((void *)adev, 1218 - state); 1219 - if (r) 1220 - return r; 1221 - break; 1222 - } 1214 + if (adev->ip_blocks[i].version->type != block_type) 1215 + continue; 1216 + if (!adev->ip_blocks[i].version->funcs->set_powergating_state) 1217 + continue; 1218 + r = adev->ip_blocks[i].version->funcs->set_powergating_state( 1219 + (void *)adev, state); 1220 + if (r) 1221 + DRM_ERROR("set_powergating_state of IP block <%s> failed %d\n", 1222 + adev->ip_blocks[i].version->funcs->name, r); 1223 1223 } 1224 1224 return r; 1225 1225 }