Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: wwan: t7xx: Un-embed dummy device

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/

Signed-off-by: Breno Leitao <leitao@debian.org>
Link: https://lore.kernel.org/r/20240424161108.3397057-1-leitao@debian.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Breno Leitao and committed by
Jakub Kicinski
c984f374 9ac7f797

+17 -5
+16 -4
drivers/net/wwan/t7xx/t7xx_netdev.c
··· 253 253 dev->netdev_ops = &ccmni_netdev_ops; 254 254 } 255 255 256 - static void t7xx_init_netdev_napi(struct t7xx_ccmni_ctrl *ctlb) 256 + static int t7xx_init_netdev_napi(struct t7xx_ccmni_ctrl *ctlb) 257 257 { 258 258 int i; 259 259 260 260 /* one HW, but shared with multiple net devices, 261 261 * so add a dummy device for NAPI. 262 262 */ 263 - init_dummy_netdev(&ctlb->dummy_dev); 263 + ctlb->dummy_dev = alloc_netdev_dummy(0); 264 + if (!ctlb->dummy_dev) 265 + return -ENOMEM; 266 + 264 267 atomic_set(&ctlb->napi_usr_refcnt, 0); 265 268 ctlb->is_napi_en = false; 266 269 267 270 for (i = 0; i < RXQ_NUM; i++) { 268 271 ctlb->napi[i] = &ctlb->hif_ctrl->rxq[i].napi; 269 - netif_napi_add_weight(&ctlb->dummy_dev, ctlb->napi[i], t7xx_dpmaif_napi_rx_poll, 272 + netif_napi_add_weight(ctlb->dummy_dev, ctlb->napi[i], t7xx_dpmaif_napi_rx_poll, 270 273 NIC_NAPI_POLL_BUDGET); 271 274 } 275 + 276 + return 0; 272 277 } 273 278 274 279 static void t7xx_uninit_netdev_napi(struct t7xx_ccmni_ctrl *ctlb) ··· 284 279 netif_napi_del(ctlb->napi[i]); 285 280 ctlb->napi[i] = NULL; 286 281 } 282 + free_netdev(ctlb->dummy_dev); 287 283 } 288 284 289 285 static int t7xx_ccmni_wwan_newlink(void *ctxt, struct net_device *dev, u32 if_id, ··· 486 480 { 487 481 struct device *dev = &t7xx_dev->pdev->dev; 488 482 struct t7xx_ccmni_ctrl *ctlb; 483 + int ret; 489 484 490 485 ctlb = devm_kzalloc(dev, sizeof(*ctlb), GFP_KERNEL); 491 486 if (!ctlb) ··· 502 495 if (!ctlb->hif_ctrl) 503 496 return -ENOMEM; 504 497 505 - t7xx_init_netdev_napi(ctlb); 498 + ret = t7xx_init_netdev_napi(ctlb); 499 + if (ret) { 500 + t7xx_dpmaif_hif_exit(ctlb->hif_ctrl); 501 + return ret; 502 + } 503 + 506 504 init_md_status_notifier(t7xx_dev); 507 505 return 0; 508 506 }
+1 -1
drivers/net/wwan/t7xx/t7xx_netdev.h
··· 48 48 unsigned int md_sta; 49 49 struct t7xx_fsm_notifier md_status_notify; 50 50 bool wwan_is_registered; 51 - struct net_device dummy_dev; 51 + struct net_device *dummy_dev; 52 52 struct napi_struct *napi[RXQ_NUM]; 53 53 atomic_t napi_usr_refcnt; 54 54 bool is_napi_en;