Skip to contentSkip to conversation

mm/gup: further simplify __gup_device_huge()

PATCH Applied John Hubbard 2 participants 2 messages Sep 4, 2021 – Sep 16, 2021

Subsystems (2)
lore
Share & tools
lore

John Hubbard

author reviewer
#0 lore raw

PATCH 1/1 mm/gup: further simplify __gup_device_huge()

commit 6401c4eb57f9 ("mm: gup: fix potential pgmap refcnt leak in __gup_device_huge()") simplified the return paths, but didn't go quite far enough, as discussed in [1].

Remove the "ret" variable entirely, because there is enough information already available to provide the return value.

[1] https://lore.kernel.org/r/CAHk-=wgQTRX=5SkCmS+zfmpqubGHGJvXX_HgnPG8JSpHKHBMeg@mail.gmail.com

Cc Miaohe Lin <[email protected]>
Cc Claudio Imbrenda <[email protected]>
Cc Jan Kara <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
---
 mm/gup.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
mm/gup.c +1 -4
index 9935a4480710..6e62f1518c1f 100644
@@ -2241,7 +2241,6 @@ static int __gup_device_huge(unsigned long pfn, unsigned long addr,
 {
 	int nr_start = *nr;
 	struct dev_pagemap *pgmap = NULL;
-	int ret = 1;
 
 	do {
 		struct page *page = pfn_to_page(pfn);
@@ -2249,14 +2248,12 @@ static int __gup_device_huge(unsigned long pfn, unsigned long addr,
 		pgmap = get_dev_pagemap(pfn, pgmap);
 		if (unlikely(!pgmap)) {
 			undo_dev_pagemap(nr, nr_start, flags, pages);
-			ret = 0;
 			break;
 		}
 		SetPageReferenced(page);
 		pages[*nr] = page;
 		if (unlikely(!try_grab_page(page, flags))) {
 			undo_dev_pagemap(nr, nr_start, flags, pages);
-			ret = 0;
 			break;
 		}
 		(*nr)++;
@@ -2264,7 +2261,7 @@ static int __gup_device_huge(unsigned long pfn, unsigned long addr,
 	} while (addr += PAGE_SIZE, addr != end);
 
 	put_dev_pagemap(pgmap);
-	return ret;
+	return addr == end;
 }
 
 static int __gup_device_huge_pmd(pmd_t orig, pmd_t *pmdp, unsigned long addr,
Signature · 1 line
2.33.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · John Hubbard

commit 6401c4eb57f9 ("mm: gup: fix potential pgmap refcnt leak in __gup_device_huge()") simplified the return paths, but didn't go quite far enough, as discussed in [1].

Remove the "ret" variable entirely, because there is enough information already available to provide the return value.

Quoted 8 lines

[1] https://lore.kernel.org/r/CAHk-=wgQTRX=5SkCmS+zfmpqubGHGJvXX_HgnPG8JSpHKHBMeg@mail.gmail.com

Cc Miaohe Lin <[email protected]>
Cc Claudio Imbrenda <[email protected]>
Cc Jan Kara <[email protected]>
Cc Kirill A. Shutemov <[email protected]>

Looks sane. Feel free to add:

Honza

Quoted 43 lines
---
 mm/gup.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
mm/gup.c +1 -4
index 9935a4480710..6e62f1518c1f 100644
@@ -2241,7 +2241,6 @@ static int __gup_device_huge(unsigned long pfn, unsigned long addr,
 {
 	int nr_start = *nr;
 	struct dev_pagemap *pgmap = NULL;
-	int ret = 1;
 
 	do {
 		struct page *page = pfn_to_page(pfn);
@@ -2249,14 +2248,12 @@ static int __gup_device_huge(unsigned long pfn, unsigned long addr,
 		pgmap = get_dev_pagemap(pfn, pgmap);
 		if (unlikely(!pgmap)) {
 			undo_dev_pagemap(nr, nr_start, flags, pages);
-			ret = 0;
 			break;
 		}
 		SetPageReferenced(page);
 		pages[*nr] = page;
 		if (unlikely(!try_grab_page(page, flags))) {
 			undo_dev_pagemap(nr, nr_start, flags, pages);
-			ret = 0;
 			break;
 		}
 		(*nr)++;
@@ -2264,7 +2261,7 @@ static int __gup_device_huge(unsigned long pfn, unsigned long addr,
 	} while (addr += PAGE_SIZE, addr != end);
 
 	put_dev_pagemap(pgmap);
-	return ret;
+	return addr == end;
 }
 
 static int __gup_device_huge_pmd(pmd_t orig, pmd_t *pmdp, unsigned long addr,
Signature · 1 line
2.33.0
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR