]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - queue-5.1/net-hns3-fix-for-dereferencing-before-null-checking.patch
5.1-stable patches
[thirdparty/kernel/stable-queue.git] / queue-5.1 / net-hns3-fix-for-dereferencing-before-null-checking.patch
CommitLineData
12670874
SL
1From 704a0a18e037aef812d0a5b6a4dbe81e1682318b Mon Sep 17 00:00:00 2001
2From: Yunsheng Lin <linyunsheng@huawei.com>
3Date: Thu, 13 Jun 2019 17:12:29 +0800
4Subject: net: hns3: fix for dereferencing before null checking
5
6[ Upstream commit 757188005f905664b0186b88cf26a7e844190a63 ]
7
8The netdev is dereferenced before null checking in the function
9hns3_setup_tc.
10
11This patch moves the dereferencing after the null checking.
12
13Fixes: 76ad4f0ee747 ("net: hns3: Add support of HNS3 Ethernet Driver for hip08 SoC")
14
15Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
16Signed-off-by: Peng Li <lipeng321@huawei.com>
17Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com>
18Signed-off-by: David S. Miller <davem@davemloft.net>
19Signed-off-by: Sasha Levin <sashal@kernel.org>
20---
21 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 7 +++++--
22 1 file changed, 5 insertions(+), 2 deletions(-)
23
24diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
25index cac17152157d..6afdd376bc03 100644
26--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
27+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
28@@ -1497,12 +1497,12 @@ static void hns3_nic_get_stats64(struct net_device *netdev,
29 static int hns3_setup_tc(struct net_device *netdev, void *type_data)
30 {
31 struct tc_mqprio_qopt_offload *mqprio_qopt = type_data;
32- struct hnae3_handle *h = hns3_get_handle(netdev);
33- struct hnae3_knic_private_info *kinfo = &h->kinfo;
34 u8 *prio_tc = mqprio_qopt->qopt.prio_tc_map;
35+ struct hnae3_knic_private_info *kinfo;
36 u8 tc = mqprio_qopt->qopt.num_tc;
37 u16 mode = mqprio_qopt->mode;
38 u8 hw = mqprio_qopt->qopt.hw;
39+ struct hnae3_handle *h;
40
41 if (!((hw == TC_MQPRIO_HW_OFFLOAD_TCS &&
42 mode == TC_MQPRIO_MODE_CHANNEL) || (!hw && tc == 0)))
43@@ -1514,6 +1514,9 @@ static int hns3_setup_tc(struct net_device *netdev, void *type_data)
44 if (!netdev)
45 return -EINVAL;
46
47+ h = hns3_get_handle(netdev);
48+ kinfo = &h->kinfo;
49+
50 return (kinfo->dcb_ops && kinfo->dcb_ops->setup_tc) ?
51 kinfo->dcb_ops->setup_tc(h, tc, prio_tc) : -EOPNOTSUPP;
52 }
53--
542.20.1
55