examples/ntb: fix error handling

Message ID 20190805050313.28719-1-xiaoyun.li@intel.com (mailing list archive)
State Superseded, archived
Headers
Series examples/ntb: fix error handling |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-Compile-Testing success Compile Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/mellanox-Performance-Testing success Performance Testing PASS

Commit Message

Li, Xiaoyun Aug. 5, 2019, 5:03 a.m. UTC
  This patch adds return value checking for fseek function to fix
error handling issue found by coverity scan.

Coverity issue: 344996
Fixes: c5eebf85badc ("examples/ntb: add example for NTB")
Cc: stable@dpdk.org

Signed-off-by: Xiaoyun Li <xiaoyun.li@intel.com>
---
 examples/ntb/ntb_fwd.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
  

Comments

Xiaolong Ye Aug. 5, 2019, 6:04 a.m. UTC | #1
On 08/05, Xiaoyun Li wrote:
>This patch adds return value checking for fseek function to fix
>error handling issue found by coverity scan.
>
>Coverity issue: 344996
>Fixes: c5eebf85badc ("examples/ntb: add example for NTB")
>Cc: stable@dpdk.org
>
>Signed-off-by: Xiaoyun Li <xiaoyun.li@intel.com>
>---
> examples/ntb/ntb_fwd.c | 13 +++++++++++--
> 1 file changed, 11 insertions(+), 2 deletions(-)
>
>diff --git a/examples/ntb/ntb_fwd.c b/examples/ntb/ntb_fwd.c
>index c169f01a3..671b13f50 100644
>--- a/examples/ntb/ntb_fwd.c
>+++ b/examples/ntb/ntb_fwd.c
>@@ -107,6 +107,7 @@ cmd_sendfile_parsed(void *parsed_result,
> 	uint8_t *buff;
> 	uint32_t val;
> 	FILE *file;
>+	int status;
> 
> 	if (!rte_rawdevs[dev_id].started) {
> 		printf("Device needs to be up first. Try later.\n");
>@@ -125,9 +126,17 @@ cmd_sendfile_parsed(void *parsed_result,
> 		return;
> 	}
> 
>-	fseek(file, 0, SEEK_END);
>+	status = fseek(file, 0, SEEK_END);
>+	if (status) {

How about simplify to 

	if (fseek(file, 0, SEEK_END) < 0)

>+		printf("Fail to get file size.\n");
>+		return;
>+	}
> 	size = ftell(file);
>-	fseek(file, 0, SEEK_SET);
>+	status = fseek(file, 0, SEEK_SET);
>+	if (status) {

Ditto.

Thanks,
Xiaolong
>+		printf("Fail to get file size.\n");
>+		return;
>+	}
> 
> 	/**
> 	 * No FIFO now. Only test memory. Limit sending file
>-- 
>2.17.1
>
  
Li, Xiaoyun Aug. 5, 2019, 6:19 a.m. UTC | #2
Sure. Will update in v2. Thx.

> -----Original Message-----
> From: Ye, Xiaolong
> Sent: Monday, August 5, 2019 14:05
> To: Li, Xiaoyun <xiaoyun.li@intel.com>
> Cc: Wu, Jingjing <jingjing.wu@intel.com>; dev@dpdk.org; stable@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH] examples/ntb: fix error handling
> 
> On 08/05, Xiaoyun Li wrote:
> >This patch adds return value checking for fseek function to fix error
> >handling issue found by coverity scan.
> >
> >Coverity issue: 344996
> >Fixes: c5eebf85badc ("examples/ntb: add example for NTB")
> >Cc: stable@dpdk.org
> >
> >Signed-off-by: Xiaoyun Li <xiaoyun.li@intel.com>
> >---
> > examples/ntb/ntb_fwd.c | 13 +++++++++++--
> > 1 file changed, 11 insertions(+), 2 deletions(-)
> >
> >diff --git a/examples/ntb/ntb_fwd.c b/examples/ntb/ntb_fwd.c index
> >c169f01a3..671b13f50 100644
> >--- a/examples/ntb/ntb_fwd.c
> >+++ b/examples/ntb/ntb_fwd.c
> >@@ -107,6 +107,7 @@ cmd_sendfile_parsed(void *parsed_result,
> > 	uint8_t *buff;
> > 	uint32_t val;
> > 	FILE *file;
> >+	int status;
> >
> > 	if (!rte_rawdevs[dev_id].started) {
> > 		printf("Device needs to be up first. Try later.\n"); @@ -125,9
> >+126,17 @@ cmd_sendfile_parsed(void *parsed_result,
> > 		return;
> > 	}
> >
> >-	fseek(file, 0, SEEK_END);
> >+	status = fseek(file, 0, SEEK_END);
> >+	if (status) {
> 
> How about simplify to
> 
> 	if (fseek(file, 0, SEEK_END) < 0)
> 
> >+		printf("Fail to get file size.\n");
> >+		return;
> >+	}
> > 	size = ftell(file);
> >-	fseek(file, 0, SEEK_SET);
> >+	status = fseek(file, 0, SEEK_SET);
> >+	if (status) {
> 
> Ditto.
> 
> Thanks,
> Xiaolong
> >+		printf("Fail to get file size.\n");
> >+		return;
> >+	}
> >
> > 	/**
> > 	 * No FIFO now. Only test memory. Limit sending file
> >--
> >2.17.1
> >
  

Patch

diff --git a/examples/ntb/ntb_fwd.c b/examples/ntb/ntb_fwd.c
index c169f01a3..671b13f50 100644
--- a/examples/ntb/ntb_fwd.c
+++ b/examples/ntb/ntb_fwd.c
@@ -107,6 +107,7 @@  cmd_sendfile_parsed(void *parsed_result,
 	uint8_t *buff;
 	uint32_t val;
 	FILE *file;
+	int status;
 
 	if (!rte_rawdevs[dev_id].started) {
 		printf("Device needs to be up first. Try later.\n");
@@ -125,9 +126,17 @@  cmd_sendfile_parsed(void *parsed_result,
 		return;
 	}
 
-	fseek(file, 0, SEEK_END);
+	status = fseek(file, 0, SEEK_END);
+	if (status) {
+		printf("Fail to get file size.\n");
+		return;
+	}
 	size = ftell(file);
-	fseek(file, 0, SEEK_SET);
+	status = fseek(file, 0, SEEK_SET);
+	if (status) {
+		printf("Fail to get file size.\n");
+		return;
+	}
 
 	/**
 	 * No FIFO now. Only test memory. Limit sending file