Re: [patch 071/212] mm: gup: fix potential pgmap refcnt leak in __gup_device_huge()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9/3/21 9:35 AM, Linus Torvalds wrote:
On Thu, Sep 2, 2021 at 2:53 PM Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:

+       int ret = 1;
..
+                       ret = 0;
+                       break;
..
+                       ret = 0;
+                       break;
..
+       return ret;

Hmm. I think "ret" is unnecessary, and this could just have been

         return addr == end;

at the end to check that we did it all.

No?


Yes, definitely.

So, to be extra clear even though this is tiny and trivial: this incremental
change, on top of the current patch, looks good to me:

diff --git a/mm/gup.c b/mm/gup.c
index 7a406d79bd2e..74142c621556 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -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,



thanks,
--
John Hubbard
NVIDIA



[Index of Archives]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux