From: Bart Van Assche Date: Sun, 13 Nov 2022 23:10:10 +0000 (-0800) Subject: os/os.h: Improve cpus_configured() X-Git-Tag: fio-3.34~104^2 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=192cdbe2e4fc521aa6c90a6ff4ac62145be60dbb;p=fio.git 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 --- 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