Skip to contentSkip to conversation

libxfs: libxfs_nproc should never return negative numbers

PATCH In review Darrick J. Wong 2 participants 2 messages Dec 6, 2017 – Dec 7, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxfs: libxfs_nproc should never return negative numbers

From: Darrick J. Wong <[email protected]>

Prevent libxfs_nproc from returning a negative/zero CPU count if platform_nproc happens to error out.

Fixes-coverity-id: 1425909
Fixes-coverity-id: 1425910
Fixes-coverity-id: 1425913

---
 libxfs/init.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
libxfs/init.c +6 -1
index a007b3b..302f088 100644
@@ -910,7 +910,12 @@ libxfs_report(FILE *fp)
 int
 libxfs_nproc(void)
 {
-	return platform_nproc();
+	int	nr;
+
+	nr = platform_nproc();
+	if (nr < 1)
+		nr = 1;
+	return nr;
 }
 
 unsigned long
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Prevent libxfs_nproc from returning a negative/zero CPU count if platform_nproc happens to error out.

Fixes-coverity-id: 1425909
Fixes-coverity-id: 1425910
Fixes-coverity-id: 1425913

3 birds, one stone, probably worth it :)

Quoted 24 lines
---
 libxfs/init.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
libxfs/init.c +6 -1
index a007b3b..302f088 100644
@@ -910,7 +910,12 @@ libxfs_report(FILE *fp)
 int
 libxfs_nproc(void)
 {
-	return platform_nproc();
+	int	nr;
+
+	nr = platform_nproc();
+	if (nr < 1)
+		nr = 1;
+	return nr;
 }
 
 unsigned long