Commit b0c14887 authored by Haibin Lu's avatar Haibin Lu Committed by Jie Liu
Browse files

UNIC: The driver loading process is terminated when the guid fails to be obtained.

driver inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I8GIXF


CVE: NA

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

If the guid fails to be obtained during driver loading,
the firmware is faulty. In this case, stop the driver
loading process.

This patch changes the return values of hns3_unic_init()
and hns3_unic_init_guid() from void to int. When
hns3_unic_init_guid() fails to be executed, The driver
terminates its initialization process and releases the
previously applied resources.

Signed-off-by: default avatarHaibin Lu <luhaibin10@hisilicon.com>
parent 9ad63641
Loading
Loading
Loading
Loading
+18 −4
Original line number Diff line number Diff line
@@ -5745,8 +5745,14 @@ static int hns3_client_init(struct hnae3_handle *handle)

	netdev->max_mtu = HNS3_MAX_MTU(ae_dev->dev_specs.max_frm_size);
#ifdef CONFIG_HNS3_UBL
	if (hns3_ubl_supported(handle))
		hns3_unic_init(netdev);
	if (hns3_ubl_supported(handle)) {
		ret = hns3_unic_init(netdev);
		if (ret) {
			dev_err(priv->dev, "failed to init unic, ret = %d\n",
				ret);
			goto out_dbg_init;
		}
	}
#endif

	hns3_state_init(handle);
@@ -5767,6 +5773,7 @@ static int hns3_client_init(struct hnae3_handle *handle)

out_reg_netdev_fail:
	hns3_state_uninit(handle);
out_dbg_init:
	hns3_dbg_uninit(handle);
	hns3_client_stop(handle);
out_client_start:
@@ -6065,14 +6072,21 @@ static int hns3_reset_notify_init_enet(struct hnae3_handle *handle)
		goto err_client_start_fail;
	}
#ifdef CONFIG_HNS3_UBL
	if (hns3_ubl_supported(handle))
		hns3_unic_init_guid(netdev);
	if (hns3_ubl_supported(handle)) {
		ret = hns3_unic_init_guid(netdev);
		if (ret) {
			dev_err(priv->dev, "init guid failed! ret=%d\n", ret);
			goto err_init_guid_fail;
		}
	}
#endif

	set_bit(HNS3_NIC_STATE_INITED, &priv->state);

	return ret;

err_init_guid_fail:
	hns3_client_stop(handle);
err_client_start_fail:
	hns3_free_rx_cpu_rmap(netdev);
	hns3_nic_uninit_irq(priv);
+14 −7
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ void hns3_unic_set_default_cc(struct sk_buff *skb)
		ubl->h_cc = htons(UNIC_CC_DEFAULT_FECN_MODE);
}

void hns3_unic_init(struct net_device *netdev)
int hns3_unic_init(struct net_device *netdev)
{
	struct hnae3_handle *h = hns3_get_handle(netdev);
	struct pci_dev *pdev = h->pdev;
@@ -53,7 +53,7 @@ void hns3_unic_init(struct net_device *netdev)
	netdev->flags &= ~(IFF_BROADCAST | IFF_MULTICAST);
	netdev->max_mtu = ae_dev->dev_specs.max_frm_size;

	hns3_unic_init_guid(netdev);
	return hns3_unic_init_guid(netdev);
}

/**
@@ -324,7 +324,7 @@ void hns3_unic_set_rx_mode(struct net_device *netdev)
	hns3_request_update_promisc_mode(h);
}

void hns3_unic_init_guid(struct net_device *netdev)
int hns3_unic_init_guid(struct net_device *netdev)
{
	const u8 bc_guid[HNS3_SIMPLE_GUID_LEN] = {0xff, 0xff, 0xff, 0xff,
						  0xff, 0xff};
@@ -336,13 +336,19 @@ void hns3_unic_init_guid(struct net_device *netdev)
	if (!h->ae_algo->ops->get_func_guid ||
	    !h->ae_algo->ops->set_func_guid) {
		netdev_err(netdev, "the guid handlers may not exist\n");
		return;
		return -EOPNOTSUPP;
	}

	ret = h->ae_algo->ops->get_func_guid(h, temp_guid_addr);
	if (ret) {
		netdev_err(netdev, "get function guid fail, ret = %d!\n", ret);
		return;
		return ret;
	}

	ret = hns3_unic_add_mc_guid(netdev, bc_guid);
	if (ret) {
		netdev_err(netdev, "add mc guid fail, ret = %d!\n", ret);
		return ret;
	}

	memcpy(netdev->dev_addr, temp_guid_addr, netdev->addr_len);
@@ -351,8 +357,9 @@ void hns3_unic_init_guid(struct net_device *netdev)
	ret = h->ae_algo->ops->set_func_guid(h, netdev->dev_addr);
	if (ret) {
		netdev_err(netdev, "set function guid fail, ret = %d\n", ret);
		return;
		hns3_unic_del_mc_guid(netdev, bc_guid);
		return ret;
	}

	hns3_unic_add_mc_guid(netdev, bc_guid);
	return 0;
}
+2 −2
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ static inline void hns3_unic_format_sim_guid_addr(char *format_simple_guid_addr,
}

void hns3_unic_set_default_cc(struct sk_buff *skb);
void hns3_unic_init(struct net_device *netdev);
int hns3_unic_init(struct net_device *netdev);
void hns3_unic_set_l3_type(struct sk_buff *skb, u32 *type_cs_vlan_tso);
u8 hns3_unic_get_l3_type(struct net_device *netdev, u32 ol_info, u32 l234info);
void hns3_unic_lp_setup_skb(struct sk_buff *skb);
@@ -60,6 +60,6 @@ void hns3_unic_lb_check_skb_data(struct hns3_enet_ring *ring,
void register_ipaddr_notifier(void);
void unregister_ipaddr_notifier(void);
void hns3_unic_set_rx_mode(struct net_device *netdev);
void hns3_unic_init_guid(struct net_device *netdev);
int hns3_unic_init_guid(struct net_device *netdev);

#endif