linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] userfaultfd/selftests: use swap() instead of open coding it
@ 2022-04-07 12:31 Guo Zhengkui
  2022-04-07 13:17 ` Muchun Song
  2022-04-07 18:45 ` Shuah Khan
  0 siblings, 2 replies; 3+ messages in thread
From: Guo Zhengkui @ 2022-04-07 12:31 UTC (permalink / raw)
  To: Andrew Morton, Shuah Khan, open list:MEMORY MANAGEMENT,
	open list:KERNEL SELFTEST FRAMEWORK, open list
  Cc: zhengkui_guo, Guo Zhengkui

Address the following coccicheck warning:

tools/testing/selftests/vm/userfaultfd.c:1536:21-22: WARNING opportunity
for swap().
tools/testing/selftests/vm/userfaultfd.c:1540:33-34: WARNING opportunity
for swap().

by using swap() for the swapping of variable values and drop
`tmp_area` that is not needed any more.

`swap()` macro in userfaultfd.c is introduced in commit 681696862bc18
("selftests: vm: remove dependecy from internal kernel macros")

It has been tested with gcc (Debian 8.3.0-6) 8.3.0.

Signed-off-by: Guo Zhengkui <guozhengkui@vivo.com>
---
 tools/testing/selftests/vm/userfaultfd.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c
index 92a4516f8f0d..7aba3ced7545 100644
--- a/tools/testing/selftests/vm/userfaultfd.c
+++ b/tools/testing/selftests/vm/userfaultfd.c
@@ -1422,7 +1422,6 @@ static void userfaultfd_pagemap_test(unsigned int test_pgsize)
 static int userfaultfd_stress(void)
 {
 	void *area;
-	char *tmp_area;
 	unsigned long nr;
 	struct uffdio_register uffdio_register;
 	struct uffd_stats uffd_stats[nr_cpus];
@@ -1533,13 +1532,9 @@ static int userfaultfd_stress(void)
 					    count_verify[nr], nr);
 
 		/* prepare next bounce */
-		tmp_area = area_src;
-		area_src = area_dst;
-		area_dst = tmp_area;
+		swap(area_src, area_dst);
 
-		tmp_area = area_src_alias;
-		area_src_alias = area_dst_alias;
-		area_dst_alias = tmp_area;
+		swap(area_src_alias, area_dst_alias);
 
 		uffd_stats_report(uffd_stats, nr_cpus);
 	}
-- 
2.20.1



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

* Re: [PATCH] userfaultfd/selftests: use swap() instead of open coding it
  2022-04-07 12:31 [PATCH] userfaultfd/selftests: use swap() instead of open coding it Guo Zhengkui
@ 2022-04-07 13:17 ` Muchun Song
  2022-04-07 18:45 ` Shuah Khan
  1 sibling, 0 replies; 3+ messages in thread
From: Muchun Song @ 2022-04-07 13:17 UTC (permalink / raw)
  To: Guo Zhengkui
  Cc: Andrew Morton, Shuah Khan, open list:MEMORY MANAGEMENT,
	open list:KERNEL SELFTEST FRAMEWORK, open list, zhengkui_guo

On Thu, Apr 07, 2022 at 08:31:41PM +0800, Guo Zhengkui wrote:
> Address the following coccicheck warning:
> 
> tools/testing/selftests/vm/userfaultfd.c:1536:21-22: WARNING opportunity
> for swap().
> tools/testing/selftests/vm/userfaultfd.c:1540:33-34: WARNING opportunity
> for swap().
> 
> by using swap() for the swapping of variable values and drop
> `tmp_area` that is not needed any more.
> 
> `swap()` macro in userfaultfd.c is introduced in commit 681696862bc18
> ("selftests: vm: remove dependecy from internal kernel macros")
> 
> It has been tested with gcc (Debian 8.3.0-6) 8.3.0.
> 
> Signed-off-by: Guo Zhengkui <guozhengkui@vivo.com>

Reviewed-by: Muchun Song <songmuchun@bytedance.com>

Thanks.


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

* Re: [PATCH] userfaultfd/selftests: use swap() instead of open coding it
  2022-04-07 12:31 [PATCH] userfaultfd/selftests: use swap() instead of open coding it Guo Zhengkui
  2022-04-07 13:17 ` Muchun Song
@ 2022-04-07 18:45 ` Shuah Khan
  1 sibling, 0 replies; 3+ messages in thread
From: Shuah Khan @ 2022-04-07 18:45 UTC (permalink / raw)
  To: Guo Zhengkui, Andrew Morton, Shuah Khan,
	open list:MEMORY MANAGEMENT, open list:KERNEL SELFTEST FRAMEWORK,
	open list
  Cc: zhengkui_guo, Shuah Khan

On 4/7/22 6:31 AM, Guo Zhengkui wrote:
> Address the following coccicheck warning:
> 
> tools/testing/selftests/vm/userfaultfd.c:1536:21-22: WARNING opportunity
> for swap().
> tools/testing/selftests/vm/userfaultfd.c:1540:33-34: WARNING opportunity
> for swap().
> 
> by using swap() for the swapping of variable values and drop
> `tmp_area` that is not needed any more.
> 
> `swap()` macro in userfaultfd.c is introduced in commit 681696862bc18
> ("selftests: vm: remove dependecy from internal kernel macros")
> 
> It has been tested with gcc (Debian 8.3.0-6) 8.3.0.
> 
> Signed-off-by: Guo Zhengkui <guozhengkui@vivo.com>

Looks good.

Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>

thanks,
-- Shuah


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

end of thread, other threads:[~2022-04-07 18:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-07 12:31 [PATCH] userfaultfd/selftests: use swap() instead of open coding it Guo Zhengkui
2022-04-07 13:17 ` Muchun Song
2022-04-07 18:45 ` Shuah Khan

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).