From f2fd7d9589703b796033e1fb600dde25593bad1b Mon Sep 17 00:00:00 2001
From: Shaozhengchao <shaozhengchao@huawei.com>
Date: Sun, 20 Oct 2019 13:51:39 +0800
Subject: [PATCH 2778/2944] openeuler: net/hinic: fix return value bug

commit 76633858616206db7ec5331d152f45b2dea8761e openEuler-1.0

driver inclusion
category:bugfix
bugzilla:4472
CVE:NA

-----------------------------------------------------------------------

fix return value bug

Signed-off-by: Shaozhengchao <shaozhengchao@huawei.com>
Reviewed-by: Wangxiaoyun <wangxiaoyun@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: Xin Hao <haoxing990@gmail.com>
Reviewed-by: Baolin Wang <baolin.wang@openanolis.org>
---
 drivers/net/ethernet/huawei/hinic/hinic_cfg.c     |  2 +-
 drivers/net/ethernet/huawei/hinic/hinic_dcb.c     |  6 +++---
 drivers/net/ethernet/huawei/hinic/hinic_ethtool.c |  4 ++--
 drivers/net/ethernet/huawei/hinic/hinic_mgmt.c    |  2 +-
 drivers/net/ethernet/huawei/hinic/hinic_nictool.c | 13 ++++++-------
 drivers/net/ethernet/huawei/hinic/hinic_rx.c      |  2 +-
 drivers/net/ethernet/huawei/hinic/hinic_tx.c      |  4 ++--
 drivers/net/ethernet/huawei/hinic/hinic_tx.h      |  2 +-
 8 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/drivers/net/ethernet/huawei/hinic/hinic_cfg.c b/drivers/net/ethernet/huawei/hinic/hinic_cfg.c
index 6662119..b2599b5 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_cfg.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_cfg.c
@@ -610,7 +610,7 @@ static int get_cap_from_pf(struct hinic_hwdev *dev, enum func_type type)
 	if (err || dev_cap.status || !out_len) {
 		sdk_err(dev->dev_hdl, "Failed to get capability from PF,  err: %d, status: 0x%x, out size: 0x%x\n",
 			err, dev_cap.status, out_len);
-		return err;
+		return -EFAULT;
 	}
 
 	parse_dev_cap(dev, &dev_cap, type);
diff --git a/drivers/net/ethernet/huawei/hinic/hinic_dcb.c b/drivers/net/ethernet/huawei/hinic/hinic_dcb.c
index 0cbdb7b..75a769b 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_dcb.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_dcb.c
@@ -1744,7 +1744,7 @@ int hinic_set_cos_up_map(struct hinic_nic_dev *nic_dev, u8 *cos_up)
 	struct hinic_nic_dev *tmp_dev;
 	u8 num_cos, old_cos_up[HINIC_DCB_COS_MAX] = {0};
 	u32 i, idx, num_dev = 0;
-	int err;
+	int err, rollback_err;
 
 	/* Save old map, in case of set failed */
 	err = hinic_get_cos_up_map(nic_dev, &num_cos, old_cos_up);
@@ -1792,8 +1792,8 @@ int hinic_set_cos_up_map(struct hinic_nic_dev *nic_dev, u8 *cos_up)
 	/* undo all settings */
 	for (i = 0; i < idx; i++) {
 		tmp_dev = (struct hinic_nic_dev *)uld_array[i];
-		err = __set_cos_up_map(tmp_dev, old_cos_up);
-		if (err)
+		rollback_err = __set_cos_up_map(tmp_dev, old_cos_up);
+		if (rollback_err)
 			nicif_err(tmp_dev, drv, tmp_dev->netdev,
 				  "Undo cos_up map to hw failed\n");
 	}
diff --git a/drivers/net/ethernet/huawei/hinic/hinic_ethtool.c b/drivers/net/ethernet/huawei/hinic/hinic_ethtool.c
index 9c28fb6..ad9faab 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_ethtool.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_ethtool.c
@@ -745,12 +745,12 @@ static int hinic_set_settings_to_hw(struct hinic_nic_dev *nic_dev,
 	char set_link_str[128] = {0};
 	int err = 0;
 
-	snprintf(set_link_str, sizeof(set_link_str) - 1, "%s",
+	snprintf(set_link_str, sizeof(set_link_str), "%s",
 		 (set_settings & HILINK_LINK_SET_AUTONEG) ?
 		 (autoneg ? "autong enable " : "autong disable ") : "");
 	if (set_settings & HILINK_LINK_SET_SPEED) {
 		speed_level = hinic_ethtool_to_hw_speed_level(speed);
-		snprintf(set_link_str, sizeof(set_link_str) - 1,
+		snprintf(set_link_str, sizeof(set_link_str),
 			 "%sspeed %d ", set_link_str, speed);
 	}
 
diff --git a/drivers/net/ethernet/huawei/hinic/hinic_mgmt.c b/drivers/net/ethernet/huawei/hinic/hinic_mgmt.c
index 8706ef0..119155b 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_mgmt.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_mgmt.c
@@ -383,7 +383,7 @@ static int send_msg_to_mgmt_sync(struct hinic_msg_pf_to_mgmt *pf_to_mgmt,
 	if (!hinic_get_chip_present_flag(pf_to_mgmt->hwdev))
 		return -EFAULT;
 
-	if (cmd_size > MAX_CMD_BUF_SIZE)
+	if (cmd_size > MAX_MSG_SZ)
 		return -EFAULT;
 
 	if (direction == HINIC_MSG_RESPONSE)
diff --git a/drivers/net/ethernet/huawei/hinic/hinic_nictool.c b/drivers/net/ethernet/huawei/hinic/hinic_nictool.c
index f611b8b..f281c19 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_nictool.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_nictool.c
@@ -586,10 +586,7 @@ static int get_loopback_mode(struct hinic_nic_dev *nic_dev, void *buf_in,
 	}
 	err = hinic_get_loopback_mode_ex(nic_dev->hwdev, &mode->loop_mode,
 					 &mode->loop_ctrl);
-	if (err)
-		return err;
-
-	return 0;
+	return err;
 }
 
 static int set_loopback_mode(struct hinic_nic_dev *nic_dev, void *buf_in,
@@ -1548,9 +1545,10 @@ static int send_to_nic_driver(struct hinic_nic_dev *nic_dev,
 	}
 	mutex_unlock(&nic_dev->nic_mutex);
 
-	if (index == num_cmds)
+	if (index == num_cmds) {
 		pr_err("Can't find callback for %d\n", cmd_type);
-
+		return -EINVAL;
+	}
 	return err;
 }
 
@@ -1899,7 +1897,7 @@ static bool is_hwdev_cmd_support(unsigned int mod,
 		break;
 
 	default:
-		break;
+		return false;
 	}
 
 	return true;
@@ -2377,6 +2375,7 @@ int nictool_k_init(void)
 				g_dev_id, NULL, HIADM_DEV_NAME);
 	if (IS_ERR(pdevice)) {
 		pr_err("Export nictool device information to user space fail\n");
+		ret = -EFAULT;
 		goto device_create_err;
 	}
 
diff --git a/drivers/net/ethernet/huawei/hinic/hinic_rx.c b/drivers/net/ethernet/huawei/hinic/hinic_rx.c
index e54ccce..ebda8ec 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_rx.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_rx.c
@@ -672,7 +672,7 @@ int hinic_rx_poll(struct hinic_rxq *rxq, int budget)
 	bool bp_en = false;
 	u16 num_wqe = 0;
 
-	while (unlikely(pkts < budget)) {
+	while (likely(pkts < budget)) {
 		sw_ci = ((u32)rxq->cons_idx) & rxq->q_mask;
 		rx_cqe = rxq->rx_info[sw_ci].cqe;
 		status = be32_to_cpu(rx_cqe->status);
diff --git a/drivers/net/ethernet/huawei/hinic/hinic_tx.c b/drivers/net/ethernet/huawei/hinic/hinic_tx.c
index af51b59..dcc4884 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_tx.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_tx.c
@@ -1275,7 +1275,7 @@ int hinic_stop_sq(struct hinic_txq *txq)
 	return -EFAULT;
 }
 
-int hinic_flush_txqs(struct net_device *netdev)
+void hinic_flush_txqs(struct net_device *netdev)
 {
 	struct hinic_nic_dev *nic_dev = netdev_priv(netdev);
 	u16 qid;
@@ -1288,5 +1288,5 @@ int hinic_flush_txqs(struct net_device *netdev)
 				  "Failed to stop sq%d\n", qid);
 	}
 
-	return 0;
+	return;
 } /*lint -e766*/
diff --git a/drivers/net/ethernet/huawei/hinic/hinic_tx.h b/drivers/net/ethernet/huawei/hinic/hinic_tx.h
index 04aeb33..2a01fab 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_tx.h
+++ b/drivers/net/ethernet/huawei/hinic/hinic_tx.h
@@ -119,6 +119,6 @@ netdev_tx_t hinic_lb_xmit_frame(struct sk_buff *skb,
 
 u8 hinic_get_vlan_pri(struct sk_buff *skb);
 
-int hinic_flush_txqs(struct net_device *netdev);
+void hinic_flush_txqs(struct net_device *netdev);
 
 #endif
-- 
1.8.3.1

