Skip to contentSkip to conversation

net/pfe: do not use a possibly NULL Pointer

PATCH In review Thierry Herbelot 3 participants 5 messages May 24, 2021 – Jun 29, 2021 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/pfe: do not use a possibly NULL Pointer

Use dev only after it was checked not to be NULL.

Fixes acd4818ea2a45 ("net/pfe: add link status update")
Cc Gagandeep Singh <[email protected]>
---
 drivers/net/pfe/pfe_ethdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/pfe/pfe_ethdev.c +2 -1
index 3135466713fb..09048e57d973 100644
@@ -578,7 +578,7 @@ static int
 pfe_eth_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused)
 {
 	int ret, ioctl_cmd = 0;
-	struct pfe_eth_priv_s *priv = dev->data->dev_private;
+	struct pfe_eth_priv_s *priv;
 	struct rte_eth_link link, old;
 	unsigned int lstatus = 1;
 
@@ -586,6 +586,7 @@ pfe_eth_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused)
 		PFE_PMD_ERR("Invalid device in link_update.\n");
 		return 0;
 	}
+	priv = dev->data->dev_private;
 
 	memset(&old, 0, sizeof(old));
 	memset(&link, 0, sizeof(struct rte_eth_link));
Signature · 1 line
2.29.2
#1 lore raw
Quoted 37 lines

-----Original Message-----
From: Thierry Herbelot <[email protected]>
Sent: Monday, May 24, 2021 2:29 PM
To: [email protected]
Cc: Thierry Herbelot <[email protected]>; Thomas Monjalon <[email protected]>; [email protected]; Gagandeep Singh <[email protected]>
Subject: [PATCH] net/pfe: do not use a possibly NULL Pointer

Use dev only after it was checked not to be NULL.

Fixes acd4818ea2a45 ("net/pfe: add link status update")
Cc Gagandeep Singh <[email protected]>
---
 drivers/net/pfe/pfe_ethdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/pfe/pfe_ethdev.c +1 -1
index 3135466713fb..09048e57d973 100644
@@ -578,7 +578,7 @@ static int
 pfe_eth_link_update(struct rte_eth_dev *dev, int wait_to_complete
 __rte_unused)
 {
 	int ret, ioctl_cmd = 0;
-	struct pfe_eth_priv_s *priv = dev->data->dev_private;
+	struct pfe_eth_priv_s *priv;
 	struct rte_eth_link link, old;
 	unsigned int lstatus = 1;

drivers/net/pfe/pfe_ethdev.c pfe_eth_link_update(struct rte_eth_dev *dev, int · line 590

Quoted 5 lines
drivers/net/pfe/pfe_ethdev.c +1 -0
@@ -586,6 +586,7 @@ pfe_eth_link_update(struct rte_eth_dev *dev, int
 wait_to_complete __rte_unused)
 		PFE_PMD_ERR("Invalid device in link_update.\n");
 		return 0;
 	}
+	priv = dev->data->dev_private;

"dev" will never be NULL here because librte_ethdev library is already doing some checks on dev before calling the link update. So please remove the if check.

Quoted 5 lines
drivers/net/pfe/pfe_ethdev.c +0 -1
 	memset(&old, 0, sizeof(old));
 	memset(&link, 0, sizeof(struct rte_eth_link));
--

2.29.2

#2 lore raw

PATCH v2 1/1 net/pfe: no need to check dev to be NULL Pointer

In reply to Thierry Herbelot

librte_ethdev library is already doing some checks on dev before calling the link update.

Fixes acd4818ea2a45 ("net/pfe: add link status update")
Cc Gagandeep Singh <[email protected]>

--
V2: rework after noting dev cannot be NULL

---
 drivers/net/pfe/pfe_ethdev.c | 5 -----
 1 file changed, 5 deletions(-)
drivers/net/pfe/pfe_ethdev.c +0 -5
index 3135466713fb..feec4d10a26e 100644
@@ -582,11 +582,6 @@ pfe_eth_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused)
 	struct rte_eth_link link, old;
 	unsigned int lstatus = 1;
 
-	if (dev == NULL) {
-		PFE_PMD_ERR("Invalid device in link_update.\n");
-		return 0;
-	}
-
 	memset(&old, 0, sizeof(old));
 	memset(&link, 0, sizeof(struct rte_eth_link));
 
Signature · 1 line
2.29.2
Acked-by on v2 1/1
#3 lore raw

Re: [dpdk-dev] [PATCH v2] net/pfe: no need to check dev to be NULL Pointer

Quoted 14 lines

-----Original Message-----
From: Thierry Herbelot <[email protected]>
Sent: Monday, May 24, 2021 3:08 PM
To: [email protected]
Cc: Thierry Herbelot <[email protected]>; Thomas Monjalon <[email protected]>; [email protected]; Gagandeep Singh <[email protected]>
Subject: [PATCH v2] net/pfe: no need to check dev to be NULL Pointer

librte_ethdev library is already doing some checks on dev before calling the link update.

Quoted 8 lines
Fixes acd4818ea2a45 ("net/pfe: add link status update")
Cc Gagandeep Singh <[email protected]>

--
V2: rework after noting dev cannot be NULL
---

Quoted 22 lines
 drivers/net/pfe/pfe_ethdev.c | 5 -----
 1 file changed, 5 deletions(-)
drivers/net/pfe/pfe_ethdev.c +0 -6
index 3135466713fb..feec4d10a26e 100644
@@ -582,11 +582,6 @@ pfe_eth_link_update(struct rte_eth_dev *dev, int
 wait_to_complete __rte_unused)
 	struct rte_eth_link link, old;
 	unsigned int lstatus = 1;
 
-	if (dev == NULL) {
-		PFE_PMD_ERR("Invalid device in link_update.\n");
-		return 0;
-	}
-
 	memset(&old, 0, sizeof(old));
 	memset(&link, 0, sizeof(struct rte_eth_link));
 
--

2.29.2

#4 lore raw

Re: [dpdk-dev] [PATCH v2] net/pfe: no need to check dev to be NULL Pointer

Quoted 18 lines · Gagandeep Singh
Quoted 18 lines

-----Original Message-----
From: Thierry Herbelot <[email protected]>
Sent: Monday, May 24, 2021 3:08 PM
To: [email protected]
Cc: Thierry Herbelot <[email protected]>; Thomas Monjalon <[email protected]>; [email protected]; Gagandeep Singh <[email protected]>
Subject: [PATCH v2] net/pfe: no need to check dev to be NULL Pointer

librte_ethdev library is already doing some checks on dev before calling the link update.

Fixes acd4818ea2a45 ("net/pfe: add link status update")
Cc Gagandeep Singh <[email protected]>
Quoted 6 lines
Quoted 4 lines

--
V2: rework after noting dev cannot be NULL
---

Applied, thanks.