Skip to contentSkip to conversation

drm/ttm: use swap macro in ttm_bo_handle_move_mem

PATCH In review Gustavo A. R. Silva 3 participants 4 messages Jul 9, 2018 – Jul 13, 2018

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

PATCH 1/1 drm/ttm: use swap macro in ttm_bo_handle_move_mem

Make use of the swap macro and remove unnecessary variable *tmp_mem*. This makes the code easier to read and maintain. Also, reduces the stack usage.

This code was detected with the help of Coccinelle.

---
 drivers/gpu/drm/ttm/ttm_bo.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +2 -5
index 5d8688e52..5142dcb 100644
@@ -287,12 +287,9 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
 
 	if (ret) {
 		if (bdev->driver->move_notify) {
-			struct ttm_mem_reg tmp_mem = *mem;
-			*mem = bo->mem;
-			bo->mem = tmp_mem;
+			swap(*mem, bo->mem);
 			bdev->driver->move_notify(bo, false, mem);
-			bo->mem = *mem;
-			*mem = tmp_mem;
+			swap(*mem, bo->mem);
 		}
 
 		goto out_err;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 17 lines · Gustavo A. R. Silva

Make use of the swap macro and remove unnecessary variable *tmp_mem*. This makes the code easier to read and maintain. Also, reduces the stack usage.

This code was detected with the help of Coccinelle.

---
 drivers/gpu/drm/ttm/ttm_bo.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +0 -0
index 5d8688e52..5142dcb 100644
@@ -287,12 +287,9 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
 

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, · line 292

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +2 -5
 	if (ret) {
 		if (bdev->driver->move_notify) {
-			struct ttm_mem_reg tmp_mem = *mem;
-			*mem = bo->mem;
-			bo->mem = tmp_mem;
+			swap(*mem, bo->mem);
 			bdev->driver->move_notify(bo, false, mem);
-			bo->mem = *mem;
-			*mem = tmp_mem;
+			swap(*mem, bo->mem);

This code assumes bo->mem is the same as tmp_mem after the call to move_notify. Is this always true?

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +0 -0
 		}
 
 		goto out_err;
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fdri-devel&data=02%7C01%7Csyeh%40vmware.com%7C3bd79878de5141b5187408d5e6326e6d%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C1%7C0%7C636668026634710967&sdata=2raJ6TBpcEM5W7hi8iCEnrEdcfJa3W5ct3tF%2BlSZLkQ%3D&reserved=0

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

#2 lore raw

Am 13.07.2018 um 04:37 schrieb Sinclair Yeh:

Quoted 18 lines · Gustavo A. R. Silva
Quoted 17 lines

Make use of the swap macro and remove unnecessary variable *tmp_mem*. This makes the code easier to read and maintain. Also, reduces the stack usage.

This code was detected with the help of Coccinelle.

---
  drivers/gpu/drm/ttm/ttm_bo.c | 7 ++-----
  1 file changed, 2 insertions(+), 5 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +0 -0
index 5d8688e52..5142dcb 100644
@@ -287,12 +287,9 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
 
Quoted 12 lines

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, · line 292

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +2 -5
  	if (ret) {
  		if (bdev->driver->move_notify) {
-			struct ttm_mem_reg tmp_mem = *mem;
-			*mem = bo->mem;
-			bo->mem = tmp_mem;
+			swap(*mem, bo->mem);
  			bdev->driver->move_notify(bo, false, mem);
-			bo->mem = *mem;
-			*mem = tmp_mem;
+			swap(*mem, bo->mem);

This code assumes bo->mem is the same as tmp_mem after the call to move_notify. Is this always true?

Actually the old code assumed that. Using the swap macro now fixed that little unclean implementation.

Christian.

Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/ttm/ttm_bo.c +0 -0
  		}
 
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo.c +0 -0
  		goto out_err;
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fdri-devel&data=02%7C01%7Csyeh%40vmware.com%7C3bd79878de5141b5187408d5e6326e6d%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C1%7C0%7C636668026634710967&sdata=2raJ6TBpcEM5W7hi8iCEnrEdcfJa3W5ct3tF%2BlSZLkQ%3D&reserved=0

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

#3 lore raw
Quoted 31 lines · Christian König

Am 13.07.2018 um 04:37 schrieb Sinclair Yeh:

Quoted 21 lines · Gustavo A. R. Silva
Quoted 20 lines

Make use of the swap macro and remove unnecessary variable *tmp_mem*. This makes the code easier to read and maintain. Also, reduces the stack usage.

This code was detected with the help of Coccinelle.

---
 drivers/gpu/drm/ttm/ttm_bo.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +0 -2
index 5d8688e52..5142dcb 100644
@@ -287,12 +287,9 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
 	if (ret) {
 		if (bdev->driver->move_notify) {
-			struct ttm_mem_reg tmp_mem = *mem;
-			*mem = bo->mem;
Quoted 8 lines

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, · line 292

Quoted 6 lines
drivers/gpu/drm/ttm/ttm_bo.c +2 -3
-			bo->mem = tmp_mem;
+			swap(*mem, bo->mem);
 			bdev->driver->move_notify(bo, false, mem);
-			bo->mem = *mem;
-			*mem = tmp_mem;
+			swap(*mem, bo->mem);

This code assumes bo->mem is the same as tmp_mem after the call to move_notify. Is this always true?

Quoted 2 lines

Actually the old code assumed that. Using the swap macro now fixed that little unclean implementation.

Ok, thanks for the clarification. This looks good to me.

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