All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: Unsigned 'nr_pages' always larger than zero
@ 2019-09-04 10:26 zhong jiang
  2019-09-04 11:24 ` Vlastimil Babka
  0 siblings, 1 reply; 26+ messages in thread
From: zhong jiang @ 2019-09-04 10:26 UTC (permalink / raw)
  To: akpm, mhocko
  Cc: anshuman.khandual, vbabka, zhongjiang, linux-mm, linux-kernel

With the help of unsigned_lesser_than_zero.cocci. Unsigned 'nr_pages"'
compare with zero. And __get_user_pages_locked will return an long value.
Hence, Convert the long to compare with zero is feasible.

Signed-off-by: zhong jiang <zhongjiang@huawei.com>
---
 mm/gup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/gup.c b/mm/gup.c
index 23a9f9c..956d5a1 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1508,7 +1508,7 @@ static long check_and_migrate_cma_pages(struct task_struct *tsk,
 						   pages, vmas, NULL,
 						   gup_flags);
 
-		if ((nr_pages > 0) && migrate_allow) {
+		if (((long)nr_pages > 0) && migrate_allow) {
 			drain_allow = true;
 			goto check_again;
 		}
-- 
1.7.12.4


^ permalink raw reply related	[flat|nested] 26+ messages in thread
* [PATCH] mm: Unsigned 'nr_pages' always larger than zero
@ 2019-10-17  3:19 zhong jiang
  2019-10-17 18:01 ` Ira Weiny
  2019-10-17 20:42 ` John Hubbard
  0 siblings, 2 replies; 26+ messages in thread
From: zhong jiang @ 2019-10-17  3:19 UTC (permalink / raw)
  To: akpm; +Cc: vbabka, jhubbard, linux-mm, zhongjiang

With the help of unsigned_lesser_than_zero.cocci. Unsigned 'nr_pages"'
compare with zero. And __get_user_pages_locked will return an long value.

The patch use a new local variable to store the return value of
__get_user_pages_locked(). Then use it to compare with zero.

Suggested-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: zhong jiang <zhongjiang@huawei.com>
---
 mm/gup.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/mm/gup.c b/mm/gup.c
index 8f236a3..1fe0ceb 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1443,6 +1443,7 @@ static long check_and_migrate_cma_pages(struct task_struct *tsk,
 	bool drain_allow = true;
 	bool migrate_allow = true;
 	LIST_HEAD(cma_page_list);
+	long ret;
 
 check_again:
 	for (i = 0; i < nr_pages;) {
@@ -1504,17 +1505,18 @@ static long check_and_migrate_cma_pages(struct task_struct *tsk,
 		 * again migrating any new CMA pages which we failed to isolate
 		 * earlier.
 		 */
-		nr_pages = __get_user_pages_locked(tsk, mm, start, nr_pages,
+		ret = __get_user_pages_locked(tsk, mm, start, nr_pages,
 						   pages, vmas, NULL,
 						   gup_flags);
 
-		if ((nr_pages > 0) && migrate_allow) {
+		nr_pages = ret;
+		if ((ret > 0) && migrate_allow) {
 			drain_allow = true;
 			goto check_again;
 		}
 	}
 
-	return nr_pages;
+	return ret;
 }
 #else
 static long check_and_migrate_cma_pages(struct task_struct *tsk,
-- 
1.7.12.4



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

end of thread, other threads:[~2019-10-21 15:11 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-04 10:26 [PATCH] mm: Unsigned 'nr_pages' always larger than zero zhong jiang
2019-09-04 11:24 ` Vlastimil Babka
2019-09-04 18:25   ` Weiny, Ira
2019-09-04 18:39     ` Matthew Wilcox
2019-09-04 18:48   ` Andrew Morton
2019-09-04 20:20     ` Weiny, Ira
2019-09-04 20:40     ` Vlastimil Babka
2019-09-05  6:18     ` zhong jiang
2019-09-05  7:19       ` Vlastimil Babka
2019-09-05  6:19     ` John Hubbard
2019-10-16  9:07       ` zhong jiang
2019-10-17  0:49         ` Andrew Morton
2019-10-17  1:38           ` zhong jiang
2019-09-04 19:01   ` Andrew Morton
2019-09-04 20:44     ` Vlastimil Babka
2019-09-05  2:05   ` zhong jiang
2019-10-17  3:19 zhong jiang
2019-10-17 18:01 ` Ira Weiny
2019-10-18  2:01   ` zhong jiang
2019-10-17 20:42 ` John Hubbard
2019-10-18  2:15   ` zhong jiang
2019-10-18 14:00   ` zhong jiang
2019-10-18 16:07     ` Alexander Duyck
2019-10-21 15:11       ` zhong jiang
2019-10-21 12:57   ` Vlastimil Babka
2019-10-21 13:47     ` zhong jiang

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.