Skip to content

Commit

Permalink
net: dsa: fix dereference on ds->dev before null check error
Browse files Browse the repository at this point in the history
Currently ds->dev is dereferenced on the assignments of pdata and
np before ds->dev is null checked, hence there is a potential null
pointer dereference on ds->dev.  Fix this by assigning pdata and
np after the ds->dev null pointer sanity check.

Addresses-Coverity: ("Dereference before null check")
Fixes: 7e99e34 ("net: dsa: remove dsa_switch_alloc helper")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Reported-by: kbuild test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Vivien Didelot <vivien.didelot@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Colin Ian King authored and David S. Miller committed Oct 28, 2019
1 parent 5b7fe93 commit 556f124
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions net/dsa/dsa2.c
Original file line number Diff line number Diff line change
Expand Up @@ -842,13 +842,16 @@ static int dsa_switch_add(struct dsa_switch *ds)

static int dsa_switch_probe(struct dsa_switch *ds)
{
struct dsa_chip_data *pdata = ds->dev->platform_data;
struct device_node *np = ds->dev->of_node;
struct dsa_chip_data *pdata;
struct device_node *np;
int err;

if (!ds->dev)
return -ENODEV;

pdata = ds->dev->platform_data;
np = ds->dev->of_node;

if (!ds->num_ports)
return -EINVAL;

Expand Down

0 comments on commit 556f124

Please sign in to comment.