[dpdk-dev] net/nfp: fix memory allocation

Message ID 1510142834-41295-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:07 p.m. UTC
  If the function actually returns a null value, a null pointer
dereference will occur.

Fixes: dd63df2bfff3 ("net/nfp: add NSP symbol resolution command")
Coverity: 195013

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

Comments

Ferruh Yigit Nov. 10, 2017, 9:39 a.m. UTC | #1
On 11/8/2017 4:07 AM, Alejandro Lucero wrote:
> If the function actually returns a null value, a null pointer
> dereference will occur.
> 
> Fixes: dd63df2bfff3 ("net/nfp: add NSP symbol resolution command")
> Coverity: 195013
> 
> 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 6ba940c..a2819a1 100644
--- a/drivers/net/nfp/nfp_nspu.c
+++ b/drivers/net/nfp/nfp_nspu.c
@@ -411,6 +411,9 @@ 
 	int ret = 0;
 
 	sym_buf = malloc(desc->buf_size);
+	if (!sym_buf)
+		return -ENOMEM;
+
 	strncpy(sym_buf, symbl, strlen(symbl));
 	ret = nspu_command(desc, NSP_CMD_GET_SYMBOL, 1, 1, sym_buf,
 			   NFP_SYM_DESC_LEN, strlen(symbl));