linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: userfaultfd: Use swap() in double_pt_lock()
@ 2024-05-31  9:16 Jiapeng Chong
  2024-05-31 10:02 ` David Hildenbrand
  0 siblings, 1 reply; 2+ messages in thread
From: Jiapeng Chong @ 2024-05-31  9:16 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, Jiapeng Chong, Abaci Robot

Use existing swap() function rather than duplicating its implementation.

./mm/userfaultfd.c:1006:13-14: WARNING opportunity for swap()

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=9266
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
 mm/userfaultfd.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
index defa5109cc62..5e7f2801698a 100644
--- a/mm/userfaultfd.c
+++ b/mm/userfaultfd.c
@@ -995,14 +995,8 @@ void double_pt_lock(spinlock_t *ptl1,
 	__acquires(ptl1)
 	__acquires(ptl2)
 {
-	spinlock_t *ptl_tmp;
-
-	if (ptl1 > ptl2) {
-		/* exchange ptl1 and ptl2 */
-		ptl_tmp = ptl1;
-		ptl1 = ptl2;
-		ptl2 = ptl_tmp;
-	}
+	if (ptl1 > ptl2)
+		swap(ptl1, ptl2);
 	/* lock in virtual address order to avoid lock inversion */
 	spin_lock(ptl1);
 	if (ptl1 != ptl2)
-- 
2.20.1.7.g153144c



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

* Re: [PATCH] mm: userfaultfd: Use swap() in double_pt_lock()
  2024-05-31  9:16 [PATCH] mm: userfaultfd: Use swap() in double_pt_lock() Jiapeng Chong
@ 2024-05-31 10:02 ` David Hildenbrand
  0 siblings, 0 replies; 2+ messages in thread
From: David Hildenbrand @ 2024-05-31 10:02 UTC (permalink / raw)
  To: Jiapeng Chong, akpm; +Cc: linux-mm, linux-kernel, Abaci Robot

On 31.05.24 11:16, Jiapeng Chong wrote:
> Use existing swap() function rather than duplicating its implementation.
> 
> ./mm/userfaultfd.c:1006:13-14: WARNING opportunity for swap()
> 
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=9266
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
>   mm/userfaultfd.c | 10 ++--------
>   1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
> index defa5109cc62..5e7f2801698a 100644
> --- a/mm/userfaultfd.c
> +++ b/mm/userfaultfd.c
> @@ -995,14 +995,8 @@ void double_pt_lock(spinlock_t *ptl1,
>   	__acquires(ptl1)
>   	__acquires(ptl2)
>   {
> -	spinlock_t *ptl_tmp;
> -
> -	if (ptl1 > ptl2) {
> -		/* exchange ptl1 and ptl2 */
> -		ptl_tmp = ptl1;
> -		ptl1 = ptl2;
> -		ptl2 = ptl_tmp;
> -	}
> +	if (ptl1 > ptl2)
> +		swap(ptl1, ptl2);
>   	/* lock in virtual address order to avoid lock inversion */
>   	spin_lock(ptl1);
>   	if (ptl1 != ptl2)

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb



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

end of thread, other threads:[~2024-05-31 10:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-31  9:16 [PATCH] mm: userfaultfd: Use swap() in double_pt_lock() Jiapeng Chong
2024-05-31 10:02 ` David Hildenbrand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox