wifi: ath12k: allocate dummy net_device dynamically
Subsystems (3)
PATCH v2 1/1 wifi: ath12k: 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 struct ath12k_ext_irq_grp by converting it into a pointer. Then use the leverage alloc_netdev_dummy() to allocate the net_device object at ath12k_pci_ext_irq_config().
The free of the device occurs at ath12k_pci_free_ext_irq().
[1] https://lore.kernel.org/all/[email protected]/
---
Changelog:
v2:
* Free all the allocated dummy devices if one of them fails to be allocated (in ath12k_pci_ext_irq_config()), as pointed by by Simon Horman.
--- drivers/net/wireless/ath/ath12k/core.h | 2 +- drivers/net/wireless/ath/ath12k/pci.c | 27 +++++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-)
drivers/net/wireless/ath/ath12k/core.h +1 -1
@@ -146,7 +146,7 @@ struct ath12k_ext_irq_grp {u32 grp_id;u64 timestamp;struct napi_struct napi; -struct net_device napi_ndev; +struct net_device *napi_ndev; };struct ath12k_smbios_bdf {
drivers/net/wireless/ath/ath12k/pci.c +22 -5
@@ -350,6 +350,7 @@ static void ath12k_pci_free_ext_irq(struct ath12k_base *ab)free_irq (ab->irq_num[irq_grp->irqs[j]], irq_grp);netif_napi_del (&irq_grp->napi); +free_netdev (irq_grp->napi_ndev); } }
@@ -560,8 +561,9 @@ static irqreturn_t ath12k_pci_ext_interrupt_handler(int irq, void *arg)static int ath12k_pci_ext_irq_config (struct ath12k_base *ab) {struct ath12k_pci *ab_pci =ath12k_pci_priv (ab); -int i, j, ret, num_vectors =0 ; +int i, j, n, ret, num_vectors =0 ;u32 user_base_data =0 , base_vector =0 , base_idx; +struct ath12k_ext_irq_grp *irq_grp; base_idx =ATH12K_PCI_IRQ_CE0_OFFSET +CE_COUNT_MAX ; ret = ath12k_pci_get_user_msi_assignment(ab, "DP",
@@ -572,13 +574,18 @@ static int ath12k_pci_ext_irq_config(struct ath12k_base *ab)return ret;for (i =0 ; i <ATH12K_EXT_IRQ_GRP_NUM_MAX ; i++) { -struct ath12k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i]; + irq_grp = &ab->ext_irq_grp[i];u32 num_irq =0 ; irq_grp->ab = ab; irq_grp->grp_id = i; -init_dummy_netdev (&irq_grp->napi_ndev); -netif_napi_add (&irq_grp->napi_ndev, &irq_grp->napi, + irq_grp->napi_ndev =alloc_netdev_dummy (0 ); +if (!irq_grp->napi_ndev) { + ret = -ENOMEM ; + goto fail_allocate; + } + +netif_napi_add (irq_grp->napi_ndev, &irq_grp->napi, ath12k_pci_ext_grp_napi_poll); if (ab->hw_params->ring_mask->tx[i] ||
@@ -611,13 +618,23 @@ static int ath12k_pci_ext_irq_config(struct ath12k_base *ab)if (ret) {ath12k_err (ab,"failed request irq %d: %d\n" , vector, ret); -return ret; + goto fail_request; } }ath12k_pci_ext_grp_disable (irq_grp); }return 0 ; + +fail_request: +/* i ->napi_ndev was properly allocated. Free it also */ + i +=1 ; +fail_allocate: +for (n =0 ; n < i; n++) { + irq_grp = &ab->ext_irq_grp[n]; +free_netdev (irq_grp->napi_ndev); + } +return ret; } static int ath12k_pci_set_irq_affinity_hint(struct ath12k_pci *ab_pci,
Signature · 1 line
2.43.0
Quoted 12 lines · Breno Leitao
Embedding
net_deviceinto structures prohibits the usage of flexible arrays in thenet_devicestructure. For more details, see the discussion at [1].Un-embed the
net_devicefrom structath12k_ext_irq_grpby converting it into a pointer. Then use the leveragealloc_netdev_dummy()to allocate thenet_deviceobject atath12k_pci_ext_irq_config().The free of the device occurs at
ath12k_pci_free_ext_irq().
Quoted 7 lines
Signed-off-by Breno Leitao <[email protected]>---
Changelog:
v2:
* Free all the allocated dummy devices if one of them fails to be allocated (inath12k_pci_ext_irq_config()), as pointed by by Simon Horman.
Thanks for the update.
Quoted 8 lines · Breno Leitao
Embedding
net_deviceinto structures prohibits the usage of flexible arrays in thenet_devicestructure. For more details, see the discussion at [1].Un-embed the
net_devicefrom structath12k_ext_irq_grpby converting it into a pointer. Then use the leveragealloc_netdev_dummy()to allocate thenet_deviceobject atath12k_pci_ext_irq_config().
Quoted 5 lines
The free of the device occurs at
ath12k_pci_free_ext_irq().Signed-off-by Breno Leitao <[email protected]>Signed-off-by Kalle Valo <[email protected]>
Patch applied to ath-next branch of ath.git, thanks.
4f9206e8c2c1 wifi: ath12k: allocate dummy net_device dynamically
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches