qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Michal Privoznik <mprivozn@redhat.com>
To: qemu-devel@nongnu.org
Cc: david@redhat.com, imammedo@redhat.com
Subject: [PATCH v2 1/4] osdep: Make qemu_madvise() to set errno in all cases
Date: Fri, 31 May 2024 09:28:57 +0200	[thread overview]
Message-ID: <e2250aa1d69faffcfd12b6d809d98b0c8157ce36.1717140354.git.mprivozn@redhat.com> (raw)
In-Reply-To: <cover.1717140354.git.mprivozn@redhat.com>

The unspoken premise of qemu_madvise() is that errno is set on
error. And it is mostly the case except for posix_madvise() which
is documented to return either zero (on success) or a positive
error number. This means, we must set errno ourselves. And while
at it, make the function return a negative value on error, just
like other error paths do.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
---
 util/osdep.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/util/osdep.c b/util/osdep.c
index e996c4744a..e42f4e8121 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -57,7 +57,12 @@ int qemu_madvise(void *addr, size_t len, int advice)
 #if defined(CONFIG_MADVISE)
     return madvise(addr, len, advice);
 #elif defined(CONFIG_POSIX_MADVISE)
-    return posix_madvise(addr, len, advice);
+    int rc = posix_madvise(addr, len, advice);
+    if (rc) {
+        errno = rc;
+        return -1;
+    }
+    return 0;
 #else
     errno = EINVAL;
     return -1;
-- 
2.44.1



  reply	other threads:[~2024-05-31  7:29 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-31  7:28 [PATCH v2 0/4] backends/hostmem: Report more errors on failures Michal Privoznik
2024-05-31  7:28 ` Michal Privoznik [this message]
2024-05-31  7:57   ` [PATCH v2 1/4] osdep: Make qemu_madvise() to set errno in all cases Philippe Mathieu-Daudé
2024-05-31  8:01     ` David Hildenbrand
2024-05-31  8:12       ` Philippe Mathieu-Daudé
2024-05-31  9:08         ` David Hildenbrand
2024-05-31 11:10           ` Michal Prívozník
2024-05-31  7:28 ` [PATCH v2 2/4] osdep: Make qemu_madvise() return ENOSYS on unsupported OSes Michal Privoznik
2024-05-31  7:48   ` Philippe Mathieu-Daudé
2024-05-31  7:53   ` David Hildenbrand
2024-05-31  8:02     ` Philippe Mathieu-Daudé
2024-05-31  7:28 ` [PATCH v2 3/4] backends/hostmem: Report error on qemu_madvise() failures Michal Privoznik
2024-05-31  7:49   ` Philippe Mathieu-Daudé
2024-05-31  9:10   ` David Hildenbrand
2024-05-31  7:29 ` [PATCH v2 4/4] backends/hostmem: Report error when memory size is unaligned Michal Privoznik
2024-05-31  7:53   ` Philippe Mathieu-Daudé
2024-06-05  7:12   ` Mario Casquero

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e2250aa1d69faffcfd12b6d809d98b0c8157ce36.1717140354.git.mprivozn@redhat.com \
    --to=mprivozn@redhat.com \
    --cc=david@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).