drm/amdgpu: add list empty check to avoid null pointer issue
Subsystems (2)
PATCH 1/1 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()
--- drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c +10 -0
@@ -80,6 +80,9 @@ static void aca_banks_release(struct aca_banks *banks) {struct aca_bank_node *node, *tmp; +if (list_empty (&banks->list)) +return ; +list_for_each_entry_safe (node, tmp, &banks->list, node) {list_del (&node->node);kvfree (node);
@@ -562,9 +565,13 @@ static void aca_error_fini(struct aca_error *aerr)struct aca_bank_error *bank_error, *tmp;mutex_lock (&aerr->lock); +if (list_empty (&aerr->list)) + goto out_unlock; +list_for_each_entry_safe (bank_error, tmp, &aerr->list, node)aca_bank_error_remove (aerr, bank_error); +out_unlock:mutex_destroy (&aerr->lock); }
@@ -680,6 +687,9 @@ static void aca_manager_fini(struct aca_handle_manager *mgr) {struct aca_handle *handle, *tmp; +if (list_empty (&mgr->list)) +return ; +list_for_each_entry_safe (handle, tmp, &mgr->list, node)amdgpu_aca_remove_handle (handle); }
Signature · 1 line
2.34.1
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 56 lines
-----Original Message-----
From: Wang, Yang(Kevin) <[email protected]>
Sent: Wednesday, August 21, 2024 2:57 PM
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Zhou1, Tao <[email protected]>
Subject: [PATCH] drm/amdgpu: add list empty check to avoid null pointer issueAdd list empty check to avoid null pointer issues in some corner cases.
-list_for_each_entry_safe()Signed-off-by Yang Wang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c +10
-1@@ -80,6 +80,9 @@ static void aca_banks_release(struct aca_banks *banks) {struct aca_bank_node *node, *tmp; +if (list_empty (&banks->list)) +return ; +list_for_each_entry_safe (node, tmp, &banks->list, node) {list_del (&node->node);kvfree (node);@@ -562,9 +565,13 @@ static void aca_error_fini(struct aca_error *aerr)struct aca_bank_error *bank_error, *tmp;mutex_lock (&aerr->lock); +if (list_empty (&aerr->list)) + goto out_unlock; +list_for_each_entry_safe (bank_error, tmp, &aerr->list, node)aca_bank_error_remove (aerr, bank_error); +out_unlock:mutex_destroy (&aerr->lock); }@@ -680,6 +687,9 @@ static void aca_manager_fini(struct aca_handle_manager *mgr) {struct aca_handle *handle, *tmp; +if (list_empty (&mgr->list)) +return ; +list_for_each_entry_safe (handle, tmp, &mgr->list, node)amdgpu_aca_remove_handle (handle); } --2.34.1
Quoted 2 lines · Yang Wang
Add list empty check to avoid null pointer issues in some corner cases.
-list_for_each_entry_safe()
What corner cases?
If the list is empty, list_for_each_entry_safe() should be mostly a no-op.
Signature · 2 lines
Earthling Michel Dänzer \ GNOME / Xwayland / Mesa developer https://redhat.com \ Libre software enthusiast