Skip to content

Commit 4416377

Browse files
Yang Wangalexdeucher
authored andcommitted
drm/amdgpu: add list empty check to avoid null pointer issue
Add list empty check to avoid null pointer issues in some corner cases. - list_for_each_entry_safe() Signed-off-by: Yang Wang <[email protected]> Reviewed-by: Tao Zhou <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 2845f51 commit 4416377

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ static void aca_banks_release(struct aca_banks *banks)
8080
{
8181
struct aca_bank_node *node, *tmp;
8282

83+
if (list_empty(&banks->list))
84+
return;
85+
8386
list_for_each_entry_safe(node, tmp, &banks->list, node) {
8487
list_del(&node->node);
8588
kvfree(node);
@@ -562,9 +565,13 @@ static void aca_error_fini(struct aca_error *aerr)
562565
struct aca_bank_error *bank_error, *tmp;
563566

564567
mutex_lock(&aerr->lock);
568+
if (list_empty(&aerr->list))
569+
goto out_unlock;
570+
565571
list_for_each_entry_safe(bank_error, tmp, &aerr->list, node)
566572
aca_bank_error_remove(aerr, bank_error);
567573

574+
out_unlock:
568575
mutex_destroy(&aerr->lock);
569576
}
570577

@@ -680,6 +687,9 @@ static void aca_manager_fini(struct aca_handle_manager *mgr)
680687
{
681688
struct aca_handle *handle, *tmp;
682689

690+
if (list_empty(&mgr->list))
691+
return;
692+
683693
list_for_each_entry_safe(handle, tmp, &mgr->list, node)
684694
amdgpu_aca_remove_handle(handle);
685695
}

0 commit comments

Comments
 (0)