Skip to contentSkip to conversation

drm/amd/powerplay: Fix error handling in smu_init_fb_allocations()

PATCH Applied Dan Carpenter 3 participants 3 messages Oct 7, 2019 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amd/powerplay: Fix error handling in smu_init_fb_allocations()

The error handling is off by one. We should not free the first "tables[i].bo" without decrementing "i" because that might result in a double free. The second problem is that when an error occurs, then the zeroth element "tables[0].bo" isn't freed.

I had make "i" signed int for the error handling to work, so I just updated "ret" as well as a clean up.

Fixes f96357a991b9 ("drm/amd/powerplay: implement smu_init(fini)_fb_allocations function")
---
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +2 -3
index f1fbbc8b77ee..c9266ea70331 100644
@@ -896,8 +896,7 @@ static int smu_init_fb_allocations(struct smu_context *smu)
 	struct amdgpu_device *adev = smu->adev;
 	struct smu_table_context *smu_table = &smu->smu_table;
 	struct smu_table *tables = smu_table->tables;
-	uint32_t i = 0;
-	int32_t ret = 0;
+	int ret, i;
 
 	for (i = 0; i < SMU_TABLE_COUNT; i++) {
 		if (tables[i].size == 0)
@@ -915,7 +914,7 @@ static int smu_init_fb_allocations(struct smu_context *smu)
 
 	return 0;
 failed:
-	for (; i > 0; i--) {
+	while (--i >= 0) {
 		if (tables[i].size == 0)
 			continue;
 		amdgpu_bo_free_kernel(&tables[i].bo,
Signature · 6 lines
2.20.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Reviewed-by on v1 1/1
#1 lore raw

thanks correct it.

Best Regards,
Kevin
________________________________
From: Dan Carpenter <[email protected]>
Sent: Monday, October 7, 2019 5:02 PM
To: Rex Zhu <[email protected]>; Wang, Kevin(Yang) <[email protected]>
Cc: Quan, Evan <[email protected]>; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhou, David(ChunMing) <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <daniel-/[email protected]>; [email protected] <amd-gfx-PD4FTy7X32lNgt0PjOBp9/[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Subject: [PATCH] drm/amd/powerplay: Fix error handling in smu_init_fb_allocations()

The error handling is off by one. We should not free the first "tables[i].bo" without decrementing "i" because that might result in a double free. The second problem is that when an error occurs, then the zeroth element "tables[0].bo" isn't freed.

I had make "i" signed int for the error handling to work, so I just updated "ret" as well as a clean up.

Fixes f96357a991b9 ("drm/amd/powerplay: implement smu_init(fini)_fb_allocations function")
---
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +2 -3
index f1fbbc8b77ee..c9266ea70331 100644
@@ -896,8 +896,7 @@ static int smu_init_fb_allocations(struct smu_context *smu)
         struct amdgpu_device *adev = smu->adev;
         struct smu_table_context *smu_table = &smu->smu_table;
         struct smu_table *tables = smu_table->tables;
-       uint32_t i = 0;
-       int32_t ret = 0;
+       int ret, i;
 
         for (i = 0; i < SMU_TABLE_COUNT; i++) {
                 if (tables[i].size == 0)
@@ -915,7 +914,7 @@ static int smu_init_fb_allocations(struct smu_context *smu)
 
         return 0;
 failed:
-       for (; i > 0; i--) {
+       while (--i >= 0) {
                 if (tables[i].size == 0)
                         continue;
                 amdgpu_bo_free_kernel(&tables[i].bo,

--
2.20.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Applied
#3 lore raw
In reply to a message not in the archive

Applied. Thanks!

Alex

Quoted 54 lines · Kevin(Yang)

thanks correct it.

Best Regards,
Kevin
________________________________
From: Dan Carpenter <[email protected]>
Sent: Monday, October 7, 2019 5:02 PM
To: Rex Zhu <[email protected]>; Wang, Kevin(Yang) <[email protected]>
Cc: Quan, Evan <[email protected]>; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhou, David(ChunMing) <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Subject: [PATCH] drm/amd/powerplay: Fix error handling in smu_init_fb_allocations()

The error handling is off by one. We should not free the first "tables[i].bo" without decrementing "i" because that might result in a double free. The second problem is that when an error occurs, then the zeroth element "tables[0].bo" isn't freed.

I had make "i" signed int for the error handling to work, so I just updated "ret" as well as a clean up.

Fixes f96357a991b9 ("drm/amd/powerplay: implement smu_init(fini)_fb_allocations function")
---
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +2 -4
index f1fbbc8b77ee..c9266ea70331 100644
@@ -896,8 +896,7 @@ static int smu_init_fb_allocations(struct smu_context *smu)
         struct amdgpu_device *adev = smu->adev;
         struct smu_table_context *smu_table = &smu->smu_table;
         struct smu_table *tables = smu_table->tables;
-       uint32_t i = 0;
-       int32_t ret = 0;
+       int ret, i;
 
         for (i = 0; i < SMU_TABLE_COUNT; i++) {
                 if (tables[i].size == 0)
@@ -915,7 +914,7 @@ static int smu_init_fb_allocations(struct smu_context *smu)
 
         return 0;
 failed:
-       for (; i > 0; i--) {
+       while (--i >= 0) {
                 if (tables[i].size == 0)
                         continue;
                 amdgpu_bo_free_kernel(&tables[i].bo,
--

2.20.1

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx