aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorMichal Privoznik <mprivozn@redhat.com>2024-06-05 12:44:55 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2024-06-08 10:33:38 +0200
commitbfb8c79f89773fb7ef6a373efebf3ce691716cb0 (patch)
tree8609adacb18e78511a335e191bc50f8fbbe066c1 /util
parent12d7d0c2496efe6325e73b04578213b8ad0af093 (diff)
downloadqemu-bfb8c79f89773fb7ef6a373efebf3ce691716cb0.zip
qemu-bfb8c79f89773fb7ef6a373efebf3ce691716cb0.tar.gz
qemu-bfb8c79f89773fb7ef6a373efebf3ce691716cb0.tar.bz2
osdep: Make qemu_madvise() to set errno in all cases
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> Message-ID: <af17113e7c1f2cc909ffd36d23f5a411b63b8764.1717584048.git.mprivozn@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'util')
-rw-r--r--util/osdep.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/util/osdep.c b/util/osdep.c
index e996c47..e42f4e8 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;