net/pfe: do not use a possibly NULL Pointer

Message ID 20210524085917.16254-1-thierry.herbelot@6wind.com (mailing list archive)
State Superseded, archived
Headers
Series net/pfe: do not use a possibly NULL Pointer |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail Compilation issues
ci/intel-Testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-mellanox-Functional fail Functional Testing issues
ci/iol-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional fail Functional Testing issues

Commit Message

Thierry Herbelot May 24, 2021, 8:59 a.m. UTC
  Use dev only after it was checked not to be NULL.

Fixes: acd4818ea2a45 ("net/pfe: add link status update")
Cc: stable@dpdk.org
Cc: Gagandeep Singh <g.singh@nxp.com>

Signed-off-by: Thierry Herbelot <thierry.herbelot@6wind.com>
---
 drivers/net/pfe/pfe_ethdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Gagandeep Singh May 24, 2021, 9:25 a.m. UTC | #1
> -----Original Message-----
> From: Thierry Herbelot <thierry.herbelot@6wind.com>
> Sent: Monday, May 24, 2021 2:29 PM
> To: dev@dpdk.org
> Cc: Thierry Herbelot <thierry.herbelot@6wind.com>; Thomas Monjalon
> <thomas@monjalon.net>; stable@dpdk.org; Gagandeep Singh
> <G.Singh@nxp.com>
> 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: stable@dpdk.org
> Cc: Gagandeep Singh <g.singh@nxp.com>
> 
> Signed-off-by: Thierry Herbelot <thierry.herbelot@6wind.com>
> ---
>  drivers/net/pfe/pfe_ethdev.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/pfe/pfe_ethdev.c b/drivers/net/pfe/pfe_ethdev.c
> index 3135466713fb..09048e57d973 100644
> --- a/drivers/net/pfe/pfe_ethdev.c
> +++ b/drivers/net/pfe/pfe_ethdev.c
> @@ -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;

"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.
> 
>  	memset(&old, 0, sizeof(old));
>  	memset(&link, 0, sizeof(struct rte_eth_link));
> --
> 2.29.2
  

Patch

diff --git a/drivers/net/pfe/pfe_ethdev.c b/drivers/net/pfe/pfe_ethdev.c
index 3135466713fb..09048e57d973 100644
--- a/drivers/net/pfe/pfe_ethdev.c
+++ b/drivers/net/pfe/pfe_ethdev.c
@@ -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));