Skip to content

Commit 4f32504

Browse files
srishanmalexdeucher
authored andcommitted
drm/amdgpu: Fix variable 'mca_funcs' dereferenced before NULL check in 'amdgpu_mca_smu_get_mca_entry()'
Fixes the below: drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c:377 amdgpu_mca_smu_get_mca_entry() warn: variable dereferenced before check 'mca_funcs' (see line 368) 357 int amdgpu_mca_smu_get_mca_entry(struct amdgpu_device *adev, enum amdgpu_mca_error_type type, 358 int idx, struct mca_bank_entry *entry) 359 { 360 const struct amdgpu_mca_smu_funcs *mca_funcs = adev->mca.mca_funcs; 361 int count; 362 363 switch (type) { 364 case AMDGPU_MCA_ERROR_TYPE_UE: 365 count = mca_funcs->max_ue_count; mca_funcs is dereferenced here. 366 break; 367 case AMDGPU_MCA_ERROR_TYPE_CE: 368 count = mca_funcs->max_ce_count; mca_funcs is dereferenced here. 369 break; 370 default: 371 return -EINVAL; 372 } 373 374 if (idx >= count) 375 return -EINVAL; 376 377 if (mca_funcs && mca_funcs->mca_get_mca_entry) ^^^^^^^^^ Checked too late! Cc: Yang Wang <[email protected]> Cc: Hawking Zhang <[email protected]> Cc: Christian König <[email protected]> Cc: Alex Deucher <[email protected]> Signed-off-by: Srinivasan Shanmugam <[email protected]> Reviewed-by: Yang Wang <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent c572abf commit 4f32504

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ int amdgpu_mca_smu_get_mca_entry(struct amdgpu_device *adev, enum amdgpu_mca_err
360360
const struct amdgpu_mca_smu_funcs *mca_funcs = adev->mca.mca_funcs;
361361
int count;
362362

363+
if (!mca_funcs || !mca_funcs->mca_get_mca_entry)
364+
return -EOPNOTSUPP;
365+
363366
switch (type) {
364367
case AMDGPU_MCA_ERROR_TYPE_UE:
365368
count = mca_funcs->max_ue_count;
@@ -374,10 +377,7 @@ int amdgpu_mca_smu_get_mca_entry(struct amdgpu_device *adev, enum amdgpu_mca_err
374377
if (idx >= count)
375378
return -EINVAL;
376379

377-
if (mca_funcs && mca_funcs->mca_get_mca_entry)
378-
return mca_funcs->mca_get_mca_entry(adev, type, idx, entry);
379-
380-
return -EOPNOTSUPP;
380+
return mca_funcs->mca_get_mca_entry(adev, type, idx, entry);
381381
}
382382

383383
#if defined(CONFIG_DEBUG_FS)

0 commit comments

Comments
 (0)