drm/amdgpu: check function points valid before use. (v3)
authorRex Zhu <Rex.Zhu@amd.com>
Wed, 22 Feb 2017 07:33:46 +0000 (15:33 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 30 Mar 2017 03:53:41 +0000 (23:53 -0400)
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>
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c

index ff0b9920ea79f1d18c02ad91e8ee601db7b352cc..a70247203f18e6fb92f262aede815919baf01713 100644 (file)
@@ -1191,13 +1191,15 @@ int amdgpu_set_clockgating_state(struct amdgpu_device *adev,
        for (i = 0; i < adev->num_ip_blocks; i++) {
                if (!adev->ip_blocks[i].status.valid)
                        continue;
-               if (adev->ip_blocks[i].version->type == block_type) {
-                       r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev,
-                                                                                    state);
-                       if (r)
-                               return r;
-                       break;
-               }
+               if (adev->ip_blocks[i].version->type != block_type)
+                       continue;
+               if (!adev->ip_blocks[i].version->funcs->set_clockgating_state)
+                       continue;
+               r = adev->ip_blocks[i].version->funcs->set_clockgating_state(
+                       (void *)adev, state);
+               if (r)
+                       DRM_ERROR("set_clockgating_state of IP block <%s> failed %d\n",
+                                 adev->ip_blocks[i].version->funcs->name, r);
        }
        return r;
 }
@@ -1211,13 +1213,15 @@ int amdgpu_set_powergating_state(struct amdgpu_device *adev,
        for (i = 0; i < adev->num_ip_blocks; i++) {
                if (!adev->ip_blocks[i].status.valid)
                        continue;
-               if (adev->ip_blocks[i].version->type == block_type) {
-                       r = adev->ip_blocks[i].version->funcs->set_powergating_state((void *)adev,
-                                                                                    state);
-                       if (r)
-                               return r;
-                       break;
-               }
+               if (adev->ip_blocks[i].version->type != block_type)
+                       continue;
+               if (!adev->ip_blocks[i].version->funcs->set_powergating_state)
+                       continue;
+               r = adev->ip_blocks[i].version->funcs->set_powergating_state(
+                       (void *)adev, state);
+               if (r)
+                       DRM_ERROR("set_powergating_state of IP block <%s> failed %d\n",
+                                 adev->ip_blocks[i].version->funcs->name, r);
        }
        return r;
 }