Commit b96cc655 authored by zhong jiang's avatar zhong jiang Committed by Linus Torvalds
Browse files

mm/gup.c: allow CMA migration to propagate errors back to caller

check_and_migrate_cma_pages() was recording the result of
__get_user_pages_locked() in an unsigned "nr_pages" variable.

Because __get_user_pages_locked() returns a signed value that can
include negative errno values, this had the effect of hiding errors.

Change check_and_migrate_cma_pages() implementation so that it uses a
signed variable instead, and propagates the results back to the caller
just as other gup internal functions do.

This was discovered with the help of unsigned_lesser_than_zero.cocci.


Signed-off-by: default avatarzhong jiang <>
Suggested-by: default avatarJohn Hubbard <>
Acked-by: default avatarVlastimil Babka <>
Reviewed-by: default avatarJohn Hubbard <>
Reviewed-by: default avatarIra Weiny <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 9266a140
......@@ -1443,6 +1443,7 @@ static long check_and_migrate_cma_pages(struct task_struct *tsk,
bool drain_allow = true;
bool migrate_allow = true;
long ret = nr_pages;
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,
if ((nr_pages > 0) && migrate_allow) {
if ((ret > 0) && migrate_allow) {
nr_pages = ret;
drain_allow = true;
goto check_again;
return nr_pages;
return ret;
static long check_and_migrate_cma_pages(struct task_struct *tsk,
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment