Skip to contentSkip to conversation

migration: mmap error check fix

PATCH In review Denis V. Lunev 3 participants 3 messages Jul 29, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 migration: mmap error check fix

From: Evgeny Yakovlev <[email protected]>

mmap man page:
"On success, mmap() returns a pointer to the mapped area. On error, the value MAP_FAILED (that is, (void *) -1) is returned, and errno is set to indicate the cause of the error."

The check in postcopy_get_tmp_page is definitely wrong and should be fixed.

---
 migration/postcopy-ram.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
migration/postcopy-ram.c +2 -1
index abe8c60..e761f3c 100644
@@ -604,7 +604,8 @@ void *postcopy_get_tmp_page(MigrationIncomingState *mis)
         mis->postcopy_tmp_page = mmap(NULL, getpagesize(),
                              PROT_READ | PROT_WRITE, MAP_PRIVATE |
                              MAP_ANONYMOUS, -1, 0);
-        if (!mis->postcopy_tmp_page) {
+        if (mis->postcopy_tmp_page == MAP_FAILED) {
+            mis->postcopy_tmp_page = NULL;
             error_report("%s: %s", __func__, strerror(errno));
             return NULL;
         }
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Denis V. Lunev

From: Evgeny Yakovlev <[email protected]>

mmap man page:
"On success, mmap() returns a pointer to the mapped area. On error, the value MAP_FAILED (that is, (void *) -1) is returned, and errno is set to indicate the cause of the error."

Quoted 7 lines

The check in postcopy_get_tmp_page is definitely wrong and should be fixed.

Amit

Reviewed-by on v1 1/1
#2 lore raw
In reply to Denis V. Lunev
Quoted 9 lines · * Denis V. Lunev ([email protected]) wrote:

From: Evgeny Yakovlev <[email protected]>

mmap man page:
"On success, mmap() returns a pointer to the mapped area. On error, the value MAP_FAILED (that is, (void *) -1) is returned, and errno is set to indicate the cause of the error."

The check in postcopy_get_tmp_page is definitely wrong and should be fixed.

Oops, nice spot!

Quoted 26 lines
---
 migration/postcopy-ram.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
migration/postcopy-ram.c +2 -1
index abe8c60..e761f3c 100644
@@ -604,7 +604,8 @@ void *postcopy_get_tmp_page(MigrationIncomingState *mis)
         mis->postcopy_tmp_page = mmap(NULL, getpagesize(),
                              PROT_READ | PROT_WRITE, MAP_PRIVATE |
                              MAP_ANONYMOUS, -1, 0);
-        if (!mis->postcopy_tmp_page) {
+        if (mis->postcopy_tmp_page == MAP_FAILED) {
+            mis->postcopy_tmp_page = NULL;
             error_report("%s: %s", __func__, strerror(errno));
             return NULL;
         }
Signature · 1 line
2.7.4

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK