From c2eedf431e13c8bbdfc5bb81e8fec912fdf643cb Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 7 Jun 2019 13:07:12 -0400 Subject: [PATCH] Fix posix_memalign and posix_fadvise calls. Almost all posix_ functions return a positive errno value (without setting errno) rather than -1 and setting errno. Most calls in this project were correct, but these two weren't. Reported-by: Hughes Signed-off-by: Theodore Ts'o --- misc/badblocks.c | 2 +- misc/e4defrag.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/misc/badblocks.c b/misc/badblocks.c index 44252dc..abf315c 100644 --- a/misc/badblocks.c +++ b/misc/badblocks.c @@ -130,7 +130,7 @@ static void *allocate_buffer(size_t size) void *ret = 0; #ifdef HAVE_POSIX_MEMALIGN - if (posix_memalign(&ret, sys_page_size, size) < 0) + if (posix_memalign(&ret, sys_page_size, size) != 0) ret = 0; #else #ifdef HAVE_MEMALIGN diff --git a/misc/e4defrag.c b/misc/e4defrag.c index b0a825f..c6c6f13 100644 --- a/misc/e4defrag.c +++ b/misc/e4defrag.c @@ -441,7 +441,8 @@ static int defrag_fadvise(int fd, struct move_extent defrag_data, offset += pagesize; continue; } - if (posix_fadvise(fd, offset, pagesize, fadvise_flag) < 0) { + if ((errno = posix_fadvise(fd, offset, + pagesize, fadvise_flag)) != 0) { if ((mode_flag & DETAIL) && flag) { perror("\tFailed to fadvise"); flag = 0; -- 1.8.3.1