linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/ttm: use swap macro in ttm_bo_handle_move_mem
@ 2018-07-09 15:24 Gustavo A. R. Silva
  2018-07-13  2:37 ` Sinclair Yeh
  0 siblings, 1 reply; 4+ messages in thread
From: Gustavo A. R. Silva @ 2018-07-09 15:24 UTC (permalink / raw)
  To: Christian Koenig, Roger He, David Airlie
  Cc: dri-devel, linux-kernel, 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.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 drivers/gpu/drm/ttm/ttm_bo.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 5d8688e52..5142dcb 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -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;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/ttm: use swap macro in ttm_bo_handle_move_mem
  2018-07-09 15:24 [PATCH] drm/ttm: use swap macro in ttm_bo_handle_move_mem Gustavo A. R. Silva
@ 2018-07-13  2:37 ` Sinclair Yeh
  2018-07-13  6:41   ` Christian König
  0 siblings, 1 reply; 4+ messages in thread
From: Sinclair Yeh @ 2018-07-13  2:37 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Christian Koenig, Roger He, David Airlie, linux-kernel, dri-devel

On Mon, Jul 09, 2018 at 10:24:47AM -0500, Gustavo A. R. Silva wrote:
> 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.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
>  drivers/gpu/drm/ttm/ttm_bo.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 5d8688e52..5142dcb 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -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);

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



>  		}
>  
>  		goto out_err;
> -- 
> 2.7.4
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fdri-devel&amp;data=02%7C01%7Csyeh%40vmware.com%7C3bd79878de5141b5187408d5e6326e6d%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C1%7C0%7C636668026634710967&amp;sdata=2raJ6TBpcEM5W7hi8iCEnrEdcfJa3W5ct3tF%2BlSZLkQ%3D&amp;reserved=0

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/ttm: use swap macro in ttm_bo_handle_move_mem
  2018-07-13  2:37 ` Sinclair Yeh
@ 2018-07-13  6:41   ` Christian König
  2018-07-13 16:01     ` Sinclair Yeh
  0 siblings, 1 reply; 4+ messages in thread
From: Christian König @ 2018-07-13  6:41 UTC (permalink / raw)
  To: Sinclair Yeh, Gustavo A. R. Silva
  Cc: Roger He, David Airlie, linux-kernel, dri-devel

Am 13.07.2018 um 04:37 schrieb Sinclair Yeh:
> On Mon, Jul 09, 2018 at 10:24:47AM -0500, Gustavo A. R. Silva wrote:
>> 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.
>>
>> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
>> ---
>>   drivers/gpu/drm/ttm/ttm_bo.c | 7 ++-----
>>   1 file changed, 2 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
>> index 5d8688e52..5142dcb 100644
>> --- a/drivers/gpu/drm/ttm/ttm_bo.c
>> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
>> @@ -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);
> 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.

>
>
>
>>   		}
>>   
>>   		goto out_err;
>> -- 
>> 2.7.4
>>
>> _______________________________________________
>> dri-devel mailing list
>> dri-devel@lists.freedesktop.org
>> https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fdri-devel&amp;data=02%7C01%7Csyeh%40vmware.com%7C3bd79878de5141b5187408d5e6326e6d%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C1%7C0%7C636668026634710967&amp;sdata=2raJ6TBpcEM5W7hi8iCEnrEdcfJa3W5ct3tF%2BlSZLkQ%3D&amp;reserved=0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/ttm: use swap macro in ttm_bo_handle_move_mem
  2018-07-13  6:41   ` Christian König
@ 2018-07-13 16:01     ` Sinclair Yeh
  0 siblings, 0 replies; 4+ messages in thread
From: Sinclair Yeh @ 2018-07-13 16:01 UTC (permalink / raw)
  To: Christian König
  Cc: Gustavo A. R. Silva, Roger He, David Airlie, linux-kernel, dri-devel

On Fri, Jul 13, 2018 at 08:41:37AM +0200, Christian König wrote:
> Am 13.07.2018 um 04:37 schrieb Sinclair Yeh:
> >On Mon, Jul 09, 2018 at 10:24:47AM -0500, Gustavo A. R. Silva wrote:
> >>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.
> >>
> >>Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> >>---
> >>  drivers/gpu/drm/ttm/ttm_bo.c | 7 ++-----
> >>  1 file changed, 2 insertions(+), 5 deletions(-)
> >>
> >>diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> >>index 5d8688e52..5142dcb 100644
> >>--- a/drivers/gpu/drm/ttm/ttm_bo.c
> >>+++ b/drivers/gpu/drm/ttm/ttm_bo.c
> >>@@ -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);
> >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.

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-07-13 16:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-09 15:24 [PATCH] drm/ttm: use swap macro in ttm_bo_handle_move_mem Gustavo A. R. Silva
2018-07-13  2:37 ` Sinclair Yeh
2018-07-13  6:41   ` Christian König
2018-07-13 16:01     ` Sinclair Yeh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).