Skip to contentSkip to conversation

util/coroutine: trim sysctl's max_map_count newline before parsing

PATCH In review Hector Cao 2 participants 2 messages Oct 7

lore
Share & tools
lore

Hector Cao

author
#0 lore raw

PATCH 1/1 util/coroutine: trim sysctl's max_map_count newline before parsing

Strip trailing whitespace from max_map_count before passing it to qemu_strtoi(), allowing the strict full-string parse to succeed. Otherwise, qemu_strtoi() fails to parse the string and returns -22, making the global cache pool cap size set to UINT_MAX.

Fixes 86a637e48104 ("coroutine: cap per-thread local pool size")
---
 util/qemu-coroutine.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
util/qemu-coroutine.c +6 -2
index d17135f585a..5af61995437 100644
@@ -374,8 +374,12 @@ static unsigned int get_global_pool_hard_max_size(void)
      * VMAs.
      */
     if (g_file_get_contents("/proc/sys/vm/max_map_count", &contents, NULL,
-                            NULL) &&
-        qemu_strtoi(contents, NULL, 10, &max_map_count) == 0) {
+                            NULL)) {
+        /* contents has trailing newline, remove it before conversion */
+        g_strchomp(contents);
+        if (qemu_strtoi(contents, NULL, 10, &max_map_count) != 0) {
+            return UINT_MAX;
+        }
         /*
          * This is an upper bound that avoids exceeding max_map_count. Leave a
          * fixed amount for non-coroutine users like library dependencies,
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Hector Cao

Strip trailing whitespace from max_map_count before passing it to qemu_strtoi(), allowing the strict full-string parse to succeed. Otherwise, qemu_strtoi() fails to parse the string and returns -22, making the global cache pool cap size set to UINT_MAX.

Fixes 86a637e48104 ("coroutine: cap per-thread local pool size")
---
 util/qemu-coroutine.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Quoted 9 lines
util/qemu-coroutine.c +0 -1
index d17135f585a..5af61995437 100644
@@ -374,8 +374,12 @@ static unsigned int get_global_pool_hard_max_size(void)
      * VMAs.
      */
     if (g_file_get_contents("/proc/sys/vm/max_map_count", &contents, NULL,
-                            NULL) &&

util/qemu-coroutine.c static unsigned int get_global_pool_hard_max_size(void) · line 385

Quoted 10 lines
util/qemu-coroutine.c +6 -1
-        qemu_strtoi(contents, NULL, 10, &max_map_count) == 0) {
+                            NULL)) {
+        /* contents has trailing newline, remove it before conversion */
+        g_strchomp(contents);
+        if (qemu_strtoi(contents, NULL, 10, &max_map_count) != 0) {
+            return UINT_MAX;
+        }
         /*
          * This is an upper bound that avoids exceeding max_map_count. Leave a
          * fixed amount for non-coroutine users like library dependencies,

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|