wifi: rtw89: Un-embed dummy device
authorBreno Leitao <leitao@debian.org>
Wed, 24 Apr 2024 18:23:49 +0000 (11:23 -0700)
committerPing-Ke Shih <pkshih@realtek.com>
Thu, 9 May 2024 06:04:09 +0000 (14:04 +0800)
Embedding net_device into structures prohibits the usage of flexible
arrays in the net_device structure. For more details, see the discussion
at [1].

Un-embed the net_device from the private struct by converting it
into a pointer. Then use the leverage the new alloc_netdev_dummy()
helper to allocate and initialize dummy devices.

[1] https://lore.kernel.org/all/20240229225910.79e224cf@kernel.org/

Tested with RTL8852BE, RTL8852C and RTL8922AE.

Signed-off-by: Breno Leitao <leitao@debian.org>
Acked-by: Ping-Ke Shih <pkshih@realtek.com>
Tested-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Link: https://msgid.link/20240424182351.3936556-1-leitao@debian.org
drivers/net/wireless/realtek/rtw89/core.c
drivers/net/wireless/realtek/rtw89/core.h
drivers/net/wireless/realtek/rtw89/pci.c

index ddc390d24ec1a6e6e230574a570ade00a115ea90..53997fa51ba0d0ad412bc7f1d3e6a55c5260dd4a 100644 (file)
@@ -2492,11 +2492,15 @@ void rtw89_core_napi_stop(struct rtw89_dev *rtwdev)
 }
 EXPORT_SYMBOL(rtw89_core_napi_stop);
 
-void rtw89_core_napi_init(struct rtw89_dev *rtwdev)
+int rtw89_core_napi_init(struct rtw89_dev *rtwdev)
 {
-       init_dummy_netdev(&rtwdev->netdev);
-       netif_napi_add(&rtwdev->netdev, &rtwdev->napi,
+       rtwdev->netdev = alloc_netdev_dummy(0);
+       if (!rtwdev->netdev)
+               return -ENOMEM;
+
+       netif_napi_add(rtwdev->netdev, &rtwdev->napi,
                       rtwdev->hci.ops->napi_poll);
+       return 0;
 }
 EXPORT_SYMBOL(rtw89_core_napi_init);
 
@@ -2504,6 +2508,7 @@ void rtw89_core_napi_deinit(struct rtw89_dev *rtwdev)
 {
        rtw89_core_napi_stop(rtwdev);
        netif_napi_del(&rtwdev->napi);
+       free_netdev(rtwdev->netdev);
 }
 EXPORT_SYMBOL(rtw89_core_napi_deinit);
 
index 112bdd95fc6ead4a3c0981ebe9d10a9998390764..0648458110cef650a2b06f8d94f5ca83f8a460b1 100644 (file)
@@ -5469,7 +5469,7 @@ struct rtw89_dev {
        struct rtw89_wow_param wow;
 
        /* napi structure */
-       struct net_device netdev;
+       struct net_device *netdev;
        struct napi_struct napi;
        int napi_budget_countdown;
 
@@ -6441,7 +6441,7 @@ void rtw89_core_query_rxdesc_v2(struct rtw89_dev *rtwdev,
                                u8 *data, u32 data_offset);
 void rtw89_core_napi_start(struct rtw89_dev *rtwdev);
 void rtw89_core_napi_stop(struct rtw89_dev *rtwdev);
-void rtw89_core_napi_init(struct rtw89_dev *rtwdev);
+int rtw89_core_napi_init(struct rtw89_dev *rtwdev);
 void rtw89_core_napi_deinit(struct rtw89_dev *rtwdev);
 int rtw89_core_sta_add(struct rtw89_dev *rtwdev,
                       struct ieee80211_vif *vif,
index 7b00476a5dee355cd999807286d25271c5f14292..f93385cc20cd3d7da19dc9e9f62a7dacad12979b 100644 (file)
@@ -4293,7 +4293,11 @@ int rtw89_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
        rtw89_pci_link_cfg(rtwdev);
        rtw89_pci_l1ss_cfg(rtwdev);
 
-       rtw89_core_napi_init(rtwdev);
+       ret = rtw89_core_napi_init(rtwdev);
+       if (ret) {
+               rtw89_err(rtwdev, "failed to init napi\n");
+               goto err_clear_resource;
+       }
 
        ret = rtw89_pci_request_irq(rtwdev, pdev);
        if (ret) {