All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ext4: use swap macro in mext_page_double_lock
@ 2018-07-09 13:16 Gustavo A. R. Silva
  2018-07-22 22:19 ` Theodore Y. Ts'o
  0 siblings, 1 reply; 3+ messages in thread
From: Gustavo A. R. Silva @ 2018-07-09 13:16 UTC (permalink / raw)
  To: Theodore Ts'o, Andreas Dilger
  Cc: linux-ext4, linux-kernel, Gustavo A. R. Silva

Make use of the swap macro and remove unnecessary variable *tmp*.
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>
---
 fs/ext4/move_extent.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c
index 8e17efd..a409ff7 100644
--- a/fs/ext4/move_extent.c
+++ b/fs/ext4/move_extent.c
@@ -134,9 +134,7 @@ mext_page_double_lock(struct inode *inode1, struct inode *inode2,
 		mapping[0] = inode1->i_mapping;
 		mapping[1] = inode2->i_mapping;
 	} else {
-		pgoff_t tmp = index1;
-		index1 = index2;
-		index2 = tmp;
+		swap(index1, index2);
 		mapping[0] = inode2->i_mapping;
 		mapping[1] = inode1->i_mapping;
 	}
-- 
2.7.4


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

* Re: [PATCH] ext4: use swap macro in mext_page_double_lock
  2018-07-09 13:16 [PATCH] ext4: use swap macro in mext_page_double_lock Gustavo A. R. Silva
@ 2018-07-22 22:19 ` Theodore Y. Ts'o
  2018-07-22 23:30   ` Gustavo A. R. Silva
  0 siblings, 1 reply; 3+ messages in thread
From: Theodore Y. Ts'o @ 2018-07-22 22:19 UTC (permalink / raw)
  To: Gustavo A. R. Silva; +Cc: Andreas Dilger, linux-ext4, linux-kernel

On Mon, Jul 09, 2018 at 08:16:00AM -0500, Gustavo A. R. Silva wrote:
> Make use of the swap macro and remove unnecessary variable *tmp*.
> 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>

It doesn't actually reduce stack usage.  Look at the definition of
swap() in include/linux/kernel.h:

#define swap(a, b) \
	do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)

It removes the variable "tmp", and replace it with "__tmp".

It slightly reduces the number of lines of code, so it slightly makes
the code easier to maintainer.  But I think you are really
over-promising how much this commit helps.

Regards,

					- Ted

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

* Re: [PATCH] ext4: use swap macro in mext_page_double_lock
  2018-07-22 22:19 ` Theodore Y. Ts'o
@ 2018-07-22 23:30   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2018-07-22 23:30 UTC (permalink / raw)
  To: Theodore Y. Ts'o, Andreas Dilger, linux-ext4, linux-kernel

Hi Theodore,

On 07/22/2018 05:19 PM, Theodore Y. Ts'o wrote:
> On Mon, Jul 09, 2018 at 08:16:00AM -0500, Gustavo A. R. Silva wrote:
>> Make use of the swap macro and remove unnecessary variable *tmp*.
>> 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>
> 
> It doesn't actually reduce stack usage.  Look at the definition of
> swap() in include/linux/kernel.h:
> 
> #define swap(a, b) \
> 	do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
> 
> It removes the variable "tmp", and replace it with "__tmp".
> 
> It slightly reduces the number of lines of code, so it slightly makes
> the code easier to maintainer.  But I think you are really
> over-promising how much this commit helps.
> 
I'll remove that part from the changelog and send it again.

Thanks
--
Gustavo

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

end of thread, other threads:[~2018-07-22 23:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-09 13:16 [PATCH] ext4: use swap macro in mext_page_double_lock Gustavo A. R. Silva
2018-07-22 22:19 ` Theodore Y. Ts'o
2018-07-22 23:30   ` Gustavo A. R. Silva

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.