Skip to contentSkip to conversation

drm/amd/amdgpu: cleanup the code style a bit

PATCH Superseded Bernard Zhao 2 participants 3 messages Nov 15, 2021 1 message not in the archive

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amd/amdgpu: cleanup the code style a bit

This change is to cleanup the code style a bit.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +6 -4
index 04cf9b207e62..90070b41136a 100644
@@ -286,12 +286,14 @@ static int amdgpu_virt_init_ras_err_handler_data(struct amdgpu_device *adev)
 		return -ENOMEM;
 
 	bps = kmalloc_array(align_space, sizeof((*data)->bps), GFP_KERNEL);
+	if (!bps) {
+		kfree(*data);
+		return -ENOMEM;
+	}
 	bps_bo = kmalloc_array(align_space, sizeof((*data)->bps_bo), GFP_KERNEL);
-
-	if (!bps || !bps_bo) {
-		kfree(bps);
-		kfree(bps_bo);
+	if (!bps_bo) {
 		kfree(*data);
+		kfree(bps);
 		return -ENOMEM;
 	}
 
Signature · 1 line
2.33.1
#1 lore raw

Am 15.11.21 um 08:07 schrieb Bernard Zhao:

Quoted 1 line

This change is to cleanup the code style a bit.

To be honest I think the old style looked better. It took me a moment to validate this now.

What you could to instead is to have goto style error handling which would make this a bit more cleaner I think.

Christian.

Quoted 29 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +6 -4
index 04cf9b207e62..90070b41136a 100644
@@ -286,12 +286,14 @@ static int amdgpu_virt_init_ras_err_handler_data(struct amdgpu_device *adev)
  		return -ENOMEM;
 
  	bps = kmalloc_array(align_space, sizeof((*data)->bps), GFP_KERNEL);
+	if (!bps) {
+		kfree(*data);
+		return -ENOMEM;
+	}
  	bps_bo = kmalloc_array(align_space, sizeof((*data)->bps_bo), GFP_KERNEL);
-
-	if (!bps || !bps_bo) {
-		kfree(bps);
-		kfree(bps_bo);
+	if (!bps_bo) {
  		kfree(*data);
+		kfree(bps);
  		return -ENOMEM;
  	}
 

A message that is not in the archive (sent off-list or not yet received): [email protected].@PGViY2Y4YjMwLTczMTEtOWQ3Ny0wN2FiLTFiOTI3NTZjMGFlMEBnbWFpbC5jb20+

author
#3 lore raw

-----邮件原件-----
发件人: [email protected] <[email protected]> 代表 Christian K?nig
发送时间: 2021年11月15日 19:49
收件人: 赵军奎 <[email protected]>; Alex Deucher <[email protected]>; Christian König <[email protected]>; Pan, Xinhui <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>; Jingwen Chen <[email protected]>; Candice Li <[email protected]>; John Clements <[email protected]>; Monk liu <[email protected]>; Peng Ju Zhou <[email protected]>; Jiawei Gu <[email protected]>; Bokun Zhang <[email protected]>; Zhigang Luo <[email protected]>; Lee Jones <[email protected]>; [email protected]; [email protected]; [email protected] 主题: Re: [PATCH] drm/amd/amdgpu: cleanup the code style a bit

Am 15.11.21 um 08:07 schrieb Bernard Zhao:

Quoted 5 lines

This change is to cleanup the code style a bit.

To be honest I think the old style looked better. It took me a moment to validate this now.

What you could to instead is to have goto style error handling which would make this a bit more cleaner I think.

Hi
Looks like a good idea, thank you for your comments! I will resubmit a version!
BR//Bernard

Quoted 33 lines

Christian.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +6 -4
index 04cf9b207e62..90070b41136a 100644
@@ -286,12 +286,14 @@ static int amdgpu_virt_init_ras_err_handler_data(struct amdgpu_device *adev)
  		return -ENOMEM;
 
  	bps = kmalloc_array(align_space, sizeof((*data)->bps), GFP_KERNEL);
+	if (!bps) {
+		kfree(*data);
+		return -ENOMEM;
+	}
  	bps_bo = kmalloc_array(align_space, sizeof((*data)->bps_bo), 
 GFP_KERNEL);
-
-	if (!bps || !bps_bo) {
-		kfree(bps);
-		kfree(bps_bo);
+	if (!bps_bo) {
  		kfree(*data);
+		kfree(bps);
  		return -ENOMEM;
  	}