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

net: ipa: allocate dummy net_device dynamically

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>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Breno Leitao and committed by
David S. Miller
1bdab0ee b209bd6d

+9 -5
+8 -4
drivers/net/ipa/gsi.c
··· 1728 1728 gsi_channel_program(channel, true); 1729 1729 1730 1730 if (channel->toward_ipa) 1731 - netif_napi_add_tx(&gsi->dummy_dev, &channel->napi, 1731 + netif_napi_add_tx(gsi->dummy_dev, &channel->napi, 1732 1732 gsi_channel_poll); 1733 1733 else 1734 - netif_napi_add(&gsi->dummy_dev, &channel->napi, 1734 + netif_napi_add(gsi->dummy_dev, &channel->napi, 1735 1735 gsi_channel_poll); 1736 1736 1737 1737 return 0; ··· 2367 2367 /* GSI uses NAPI on all channels. Create a dummy network device 2368 2368 * for the channel NAPI contexts to be associated with. 2369 2369 */ 2370 - init_dummy_netdev(&gsi->dummy_dev); 2370 + gsi->dummy_dev = alloc_netdev_dummy(0); 2371 + if (!gsi->dummy_dev) 2372 + return -ENOMEM; 2371 2373 init_completion(&gsi->completion); 2372 2374 2373 2375 ret = gsi_reg_init(gsi, pdev); 2374 2376 if (ret) 2375 - return ret; 2377 + goto err_reg_exit; 2376 2378 2377 2379 ret = gsi_irq_init(gsi, pdev); /* No matching exit required */ 2378 2380 if (ret) ··· 2389 2387 return 0; 2390 2388 2391 2389 err_reg_exit: 2390 + free_netdev(gsi->dummy_dev); 2392 2391 gsi_reg_exit(gsi); 2393 2392 2394 2393 return ret; ··· 2400 2397 { 2401 2398 mutex_destroy(&gsi->mutex); 2402 2399 gsi_channel_exit(gsi); 2400 + free_netdev(gsi->dummy_dev); 2403 2401 gsi_reg_exit(gsi); 2404 2402 } 2405 2403
+1 -1
drivers/net/ipa/gsi.h
··· 151 151 struct mutex mutex; /* protects commands, programming */ 152 152 struct gsi_channel channel[GSI_CHANNEL_COUNT_MAX]; 153 153 struct gsi_evt_ring evt_ring[GSI_EVT_RING_COUNT_MAX]; 154 - struct net_device dummy_dev; /* needed for NAPI */ 154 + struct net_device *dummy_dev; /* needed for NAPI */ 155 155 }; 156 156 157 157 /**