From 3ed3433704932b3a8416dd4e88057c92708847fd Mon Sep 17 00:00:00 2001 From: Suraj Jaiswal Date: Mon, 8 Feb 2021 17:24:29 +0530 Subject: [PATCH] net: stmmac: Fixing KW errors - Fixing various types of kw errors. List of KW 1. Suspicious dereference of pointer before NULL check at dwmac-qcom-ethqos.c: 1396 2.Suspicious dereference of pointer before NULL check at dwmac-qcom-ethqos.c: 1354 3.Suspicious dereference of pointer before NULL check at dwmac-qcom-ethqos.c: 423 4.Suspicious dereference of pointer before NULL check at dwmac-qcom-ethqos.c: 443 5.Suspicious dereference of pointer before NULL check at dwmac-qcom-ethqos.c: 1683 6.Uninitialized variable is used at dwmac-qcom-pps.c: 46. Change-Id: I3c98c804c0fee2ecc291852e38a104ca12c42dcc Acked-by: Nagarjuna Chaganti Signed-off-by: Suraj Jaiswal --- .../stmicro/stmmac/dwmac-qcom-ethqos.c | 38 +++++++++++++------ .../ethernet/stmicro/stmmac/dwmac-qcom-pps.c | 8 +--- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c index a53fd5a8aeba..d7ac007aa71e 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 -// Copyright (c) 2018-19, Linaro Limited +// Copyright (c) 2018-19,21 Linaro Limited #include #include @@ -421,8 +421,10 @@ static int qcom_ethqos_add_ipv6addr(struct ip_params *ip_info, struct net *net = dev_net(dev); /*For valid IPv6 address*/ - if (!net || !net->genl_sock || !net->genl_sock->sk_socket) + if (!net || !net->genl_sock || !net->genl_sock->sk_socket) { ETHQOSERR("Sock is null, unable to assign ipv6 address\n"); + return -EFAULT; + } if (!net->ipv6.devconf_dflt) { ETHQOSERR("ipv6.devconf_dflt is null, schedule wq\n"); @@ -1342,17 +1344,25 @@ static ssize_t read_phy_reg_dump(struct file *file, char __user *user_buf, size_t count, loff_t *ppos) { struct qcom_ethqos *ethqos = file->private_data; + struct platform_device *pdev; + struct net_device *dev; + struct stmmac_priv *priv; unsigned int len = 0, buf_len = 2000; char *buf; ssize_t ret_cnt; int phydata = 0; int i = 0; - struct platform_device *pdev = ethqos->pdev; - struct net_device *dev = platform_get_drvdata(pdev); - struct stmmac_priv *priv = netdev_priv(dev); + if (!ethqos) { + ETHQOSERR("NULL Pointer\n"); + return -EINVAL; + } - if (!ethqos || !dev->phydev) { + pdev = ethqos->pdev; + dev = platform_get_drvdata(pdev); + priv = netdev_priv(dev); + + if (!dev->phydev) { ETHQOSERR("NULL Pointer\n"); return -EINVAL; } @@ -1386,15 +1396,22 @@ static ssize_t read_rgmii_reg_dump(struct file *file, loff_t *ppos) { struct qcom_ethqos *ethqos = file->private_data; + struct platform_device *pdev; + struct net_device *dev; unsigned int len = 0, buf_len = 2000; char *buf; ssize_t ret_cnt; int rgmii_data = 0; - struct platform_device *pdev = ethqos->pdev; - struct net_device *dev = platform_get_drvdata(pdev); + if (!ethqos) { + ETHQOSERR("NULL Pointer\n"); + return -EINVAL; + } - if (!ethqos || !dev->phydev) { + pdev = ethqos->pdev; + dev = platform_get_drvdata(pdev); + + if (!dev->phydev) { ETHQOSERR("NULL Pointer\n"); return -EINVAL; } @@ -1536,8 +1553,7 @@ static int qcom_ethqos_probe(struct platform_device *pdev) ethqos = devm_kzalloc(&pdev->dev, sizeof(*ethqos), GFP_KERNEL); if (!ethqos) { - ret = -ENOMEM; - goto err_mem; + return -ENOMEM; } ethqos->pdev = pdev; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-pps.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-pps.c index 7088f00a04dd..9914399eb383 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-pps.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-pps.c @@ -32,18 +32,14 @@ static DECLARE_WAIT_QUEUE_HEAD(avb_class_b_msg_wq); static int strlcmp(const char *s, const char *t, size_t n) { - int ret; - while (n-- && *t != '\0') { if (*s != *t) { - ret = ((unsigned char)*s - (unsigned char)*t); - n = 0; + return ((unsigned char)*s - (unsigned char)*t); } else { ++s, ++t; - ret = (unsigned char)*s; } } - return ret; + return (unsigned char)*s; } static void align_target_time_reg(u32 ch, void __iomem *ioaddr,