[dpdk-dev] net/nfp: fix null pointer check

Message ID 1510151792-45382-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, 2:36 p.m. UTC
  First, the received pointer was not checked before. Then the pointer
from malloc was not the one used in the existing check.

Fixes: ad60bca34899 ("net/nfp: read PF port MAC addr using NSP")
Coverity: 195027

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

Comments

Ferruh Yigit Nov. 10, 2017, 9:38 a.m. UTC | #1
On 11/8/2017 6:36 AM, Alejandro Lucero wrote:
> First, the received pointer was not checked before. Then the pointer
> from malloc was not the one used in the existing check.
> 
> Fixes: ad60bca34899 ("net/nfp: read PF port MAC addr using NSP")
> Coverity: 195027
> 
> 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 39d14e6..0b415fc 100644
--- a/drivers/net/nfp/nfp_nspu.c
+++ b/drivers/net/nfp/nfp_nspu.c
@@ -618,10 +618,14 @@ 
 {
 	int ret;
 
+	if (!table)
+		return -EINVAL;
+
 	RTE_LOG(INFO, PMD, "Reading hw ethernet table...\n");
+
 	/* port 0 allocates the eth table and read it using NSPU */
 	*table = malloc(NSP_ETH_TABLE_SIZE);
-	if (!table)
+	if (!*table)
 		return -ENOMEM;
 
 	ret = nspu_command(desc, NSP_CMD_READ_ETH_TABLE, 1, 0, *table,