From 192cdbe2e4fc521aa6c90a6ff4ac62145be60dbb Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 13 Nov 2022 15:10:10 -0800 Subject: [PATCH] os/os.h: Improve cpus_configured() Fix the following Coverity complaint: 1. negative_return: Calling sysconf, which might return a negative value. 2. return_negative_fn: Returning the return value of sysconf, which might be negative. Signed-off-by: Bart Van Assche --- os/os.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/os/os.h b/os/os.h index a6fde1fd..c428260c 100644 --- a/os/os.h +++ b/os/os.h @@ -355,7 +355,9 @@ static inline unsigned long long get_fs_free_size(const char *path) #ifndef FIO_HAVE_CPU_CONF_SYSCONF static inline unsigned int cpus_configured(void) { - return sysconf(_SC_NPROCESSORS_CONF); + int nr_cpus = sysconf(_SC_NPROCESSORS_CONF); + + return nr_cpus >= 1 ? nr_cpus : 1; } #endif -- 2.25.1