Unverified Commit 47e1417d authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!3257 net: hns3: add input parameters checking and arp cleancode

Merge Pull Request from: @svishen 
 
This pr add input parameters checking for hns3_ext.c and fix the arp macro error.

issue:
https://gitee.com/openeuler/kernel/issues/I8M1F3 
 
Link:https://gitee.com/openeuler/kernel/pulls/3257

 

Signed-off-by: default avatarJialin Zhang <zhangjialin11@huawei.com>
parents ca0e4f8d 9e680e08
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -34,14 +34,14 @@ static int nic_invoke_pri_ops(struct net_device *ndev, int opcode,
	struct hnae3_handle *h;
	int ret;

	if (nic_netdev_match_check(ndev))
		return -ENODEV;

	if ((!data && length) || (data && !length)) {
		netdev_err(ndev, "failed to check data and length");
		return -EINVAL;
	}

	if (nic_netdev_match_check(ndev))
		return -ENODEV;

	h = hns3_get_handle(ndev);
	if (!h->ae_algo->ops->priv_ops)
		return -EOPNOTSUPP;
@@ -58,6 +58,9 @@ static int nic_invoke_pri_ops(struct net_device *ndev, int opcode,
void nic_chip_recover_handler(struct net_device *ndev,
			      enum hnae3_event_type_custom event_t)
{
	if (nic_netdev_match_check(ndev))
		return;

	dev_info(&ndev->dev, "reset type is %d!!\n", event_t);

	if (event_t == HNAE3_PPU_POISON_CUSTOM)
@@ -100,8 +103,7 @@ int nic_set_pfc_storm_para(struct net_device *ndev, int dir, int enable,

	if (nic_check_pfc_storm_para(dir, enable, period_ms, times,
				     recovery_period_ms)) {
		dev_err(&ndev->dev,
			"set pfc storm para failed because invalid input param.\n");
		pr_err("set pfc storm para failed because invalid input param.\n");
		return -EINVAL;
	}

@@ -125,8 +127,7 @@ int nic_get_pfc_storm_para(struct net_device *ndev, int dir, int *enable,
	if (!enable || !period_ms || !times || !recovery_period_ms ||
	    (dir != HNS3_PFC_STORM_PARA_DIR_RX &&
	     dir != HNS3_PFC_STORM_PARA_DIR_TX)) {
		dev_err(&ndev->dev,
			"get pfc storm para failed because invalid input param.\n");
		pr_err("get pfc storm para failed because invalid input param.\n");
		return -EINVAL;
	}

@@ -183,6 +184,9 @@ int nic_clean_stats64(struct net_device *ndev, struct rtnl_link_stats64 *stats)
	struct hnae3_handle *h;
	int i, ret;

	if (nic_netdev_match_check(ndev))
		return -ENODEV;

	priv = netdev_priv(ndev);
	h = hns3_get_handle(ndev);
	kinfo = &h->kinfo;
@@ -222,15 +226,15 @@ int nic_set_cpu_affinity(struct net_device *ndev, cpumask_t *affinity_mask)
	int ret = 0;
	u16 i;

	if (!ndev || !affinity_mask) {
	if (nic_netdev_match_check(ndev))
		return -ENODEV;

	if (!affinity_mask) {
		netdev_err(ndev,
			   "Invalid input param when set ethernet cpu affinity\n");
		return -EINVAL;
	}

	if (nic_netdev_match_check(ndev))
		return -ENODEV;

	priv = netdev_priv(ndev);
	rtnl_lock();
	if (!test_bit(HNS3_NIC_STATE_INITED, &priv->state) ||
+2 −2
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ int hns3_handle_roh_arp_req(struct sk_buff *skb, struct hns3_nic_priv *priv)
	/* use same queue num in rx */
	ring = &priv->ring[skb->queue_mapping + h->kinfo.num_tqps];
	reply_idx = ring->arp_reply_tail;
	hns3_roh_arp_reply_idx_move_fd(reply_idx);
	reply_idx = hns3_roh_arp_reply_idx_move_fd(reply_idx);
	/* This smp_load_acquire() pairs with smp_store_release() in
	 * hns3_handle_roh_arp_reply().
	 */
@@ -150,7 +150,7 @@ void hns3_handle_roh_arp_reply(struct hns3_enet_tqp_vector *tqp_vector,
		while (smp_load_acquire(&ring->arp_reply_tail) !=
		       ring->arp_reply_head) {
			reply_idx = ring->arp_reply_head;
			hns3_roh_arp_reply_idx_move_fd(reply_idx);
			reply_idx = hns3_roh_arp_reply_idx_move_fd(reply_idx);
			arp_reply = &ring->arp_reply[reply_idx];
			skb = setup_arp_reply_skb(arp_reply, priv);
			/* This smp_store_release() pairs with
+4 −3
Original line number Diff line number Diff line
@@ -13,9 +13,10 @@
	u64_to_ether_addr((ip_addr) & HNS3_ROH_MAC_ADDR_MASK, mac)
#define hns3_roh_arp_hlen_max(skb) \
	(ETH_HLEN + arp_hdr_len((skb)->dev) + VLAN_HLEN)
#define hns3_roh_arp_reply_idx_move_fd(idx) \
	({ typeof(idx) x_ = (idx); \
	   x_ = (x_ + 1) % HNS3_APR_REPLY_LTH; })
static inline int hns3_roh_arp_reply_idx_move_fd(int idx)
{
	return (idx + 1) % HNS3_APR_REPLY_LTH;
}

void hns3_handle_roh_arp_reply(struct hns3_enet_tqp_vector *tqp_vector,
			       struct hns3_nic_priv *priv);