[dpdk-dev] net/nfp: check function return value

Message ID 1510143588-10092-1-git-send-email-alejandro.lucero@netronome.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Alejandro Lucero Nov. 8, 2017, 12:19 p.m. UTC
  The fstat function could return a value that indicates an error condition.
If this is not checked, the error condition may not be handled correctly.

Fixes: f37d8a4b67b2 ("net/nfp: add NSP FW upload command")
Coverity: 195019

Signed-off-by: Alejandro Lucero <alejandro.lucero@netronome.com>
---
 drivers/net/nfp/nfp_nspu.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
  

Comments

Ferruh Yigit Nov. 10, 2017, 9:39 a.m. UTC | #1
On 11/8/2017 4:19 AM, Alejandro Lucero wrote:
> The fstat function could return a value that indicates an error condition.
> If this is not checked, the error condition may not be handled correctly.
> 
> Fixes: f37d8a4b67b2 ("net/nfp: add NSP FW upload command")
> Coverity: 195019
> 
> Signed-off-by: Alejandro Lucero <alejandro.lucero@netronome.com>

Applied to dpdk/master, thanks.
  

Patch

diff --git a/drivers/net/nfp/nfp_nspu.c b/drivers/net/nfp/nfp_nspu.c
index 3c8cdad..39d14e6 100644
--- a/drivers/net/nfp/nfp_nspu.c
+++ b/drivers/net/nfp/nfp_nspu.c
@@ -341,7 +341,12 @@ 
 		return -ENOENT;
 	}
 
-	fstat(fw_f, &file_stat);
+	if (fstat(fw_f, &file_stat) < 0) {
+		RTE_LOG(INFO, PMD, "Firmware file %s/%s size is unknown",
+			DEFAULT_FW_PATH, DEFAULT_FW_FILENAME);
+		close(fw_f);
+		return -ENOENT;
+	}
 
 	fsize = file_stat.st_size;
 	RTE_LOG(DEBUG, PMD, "Firmware file with size: %" PRIu64 "\n",