From: Chiqijun chiqijun@huawei.com
driver inclusion category: bugfix bugzilla: 4472
-----------------------------------------------------------------------
When multiple functions execute probe/remove in parallel, it may cause repeated registration or unregistration of netdevice notifier, resulting in system oops. The driver adds a lock to ensure all registration and unregistration serial processing.
Signed-off-by: Chiqijun chiqijun@huawei.com Reviewed-by: Zengweiliang zengweiliang.zengweiliang@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- drivers/net/ethernet/huawei/hinic/hinic_main.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/drivers/net/ethernet/huawei/hinic/hinic_main.c b/drivers/net/ethernet/huawei/hinic/hinic_main.c index f367dfb..46a7800 100644 --- a/drivers/net/ethernet/huawei/hinic/hinic_main.c +++ b/drivers/net/ethernet/huawei/hinic/hinic_main.c @@ -183,6 +183,8 @@ enum hinic_rx_buff_len { int hinic_netdev_event(struct notifier_block *notifier, unsigned long event, void *ptr);
+/* used for netdev notifier register/unregister */ +DEFINE_MUTEX(g_hinic_netdev_notifiers_mutex); static int hinic_netdev_notifiers_ref_cnt; static struct notifier_block hinic_netdev_notifier = { .notifier_call = hinic_netdev_event, @@ -192,6 +194,7 @@ static void hinic_register_notifier(struct hinic_nic_dev *nic_dev) { int err;
+ mutex_lock(&g_hinic_netdev_notifiers_mutex); hinic_netdev_notifiers_ref_cnt++; if (hinic_netdev_notifiers_ref_cnt == 1) { err = register_netdevice_notifier(&hinic_netdev_notifier); @@ -201,15 +204,18 @@ static void hinic_register_notifier(struct hinic_nic_dev *nic_dev) hinic_netdev_notifiers_ref_cnt--; } } + mutex_unlock(&g_hinic_netdev_notifiers_mutex); }
static void hinic_unregister_notifier(struct hinic_nic_dev *nic_dev) { + mutex_lock(&g_hinic_netdev_notifiers_mutex); if (hinic_netdev_notifiers_ref_cnt == 1) unregister_netdevice_notifier(&hinic_netdev_notifier);
if (hinic_netdev_notifiers_ref_cnt) hinic_netdev_notifiers_ref_cnt--; + mutex_unlock(&g_hinic_netdev_notifiers_mutex); }
#define HINIC_MAX_VLAN_DEPTH_OFFLOAD_SUPPORT 2