[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20191024103218.2592-1-colin.king@canonical.com>
Date: Thu, 24 Oct 2019 11:32:18 +0100
From: Colin King <colin.king@...onical.com>
To: Andrew Lunn <andrew@...n.ch>,
Vivien Didelot <vivien.didelot@...il.com>,
Florian Fainelli <f.fainelli@...il.com>,
"David S . Miller" <davem@...emloft.net>,
Jakub Kicinski <jakub.kicinski@...ronome.com>,
netdev@...r.kernel.org
Cc: kernel-janitors@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH][next] net: dsa: fix dereference on ds->dev before null check error
From: Colin Ian King <colin.king@...onical.com>
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: 7e99e3470172 ("net: dsa: remove dsa_switch_alloc helper")
Signed-off-by: Colin Ian King <colin.king@...onical.com>
---
net/dsa/dsa2.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 1e3ac9b56c89..214dd703b0cc 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -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;
--
2.20.1
Powered by blists - more mailing lists