Commit 61cdb09f authored by Breno Leitao's avatar Breno Leitao Committed by Kalle Valo
Browse files

wifi: qtnfmac: 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 qtnf_bus by converting it
into a pointer. Then use the leverage alloc_netdev() to allocate the
net_device object at qtnf_pcie_probe(). The free of the device occurs at
qtnf_pcie_remove().

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



Signed-off-by: default avatarBreno Leitao <leitao@debian.org>
Signed-off-by: default avatarKalle Valo <kvalo@kernel.org>
Link: https://msgid.link/20240319172634.894327-1-leitao@debian.org
parent 2d5cde11
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ struct qtnf_bus {
	struct qtnf_qlink_transport trans;
	struct qtnf_hw_info hw_info;
	struct napi_struct mux_napi;
	struct net_device mux_dev;
	struct net_device *mux_dev;
	struct workqueue_struct *workqueue;
	struct workqueue_struct *hprio_workqueue;
	struct work_struct fw_work;
+11 −2
Original line number Diff line number Diff line
@@ -372,7 +372,13 @@ static int qtnf_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
		goto error;
	}

	init_dummy_netdev(&bus->mux_dev);
	bus->mux_dev = alloc_netdev(0, "dummy", NET_NAME_UNKNOWN,
				    init_dummy_netdev);
	if (!bus->mux_dev) {
		ret = -ENOMEM;
		goto error;
	}

	qtnf_pcie_init_irq(pcie_priv, use_msi);
	pcie_priv->sysctl_bar = sysctl_bar;
	pcie_priv->dmareg_bar = dmareg_bar;
@@ -381,11 +387,13 @@ static int qtnf_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)

	ret = pcie_priv->probe_cb(bus, tx_bd_size_param, rx_bd_size_param);
	if (ret)
		goto error;
		goto error_free;

	qtnf_pcie_bringup_fw_async(bus);
	return 0;

error_free:
	free_netdev(bus->mux_dev);
error:
	destroy_workqueue(pcie_priv->workqueue);
	pci_set_drvdata(pdev, NULL);
@@ -417,6 +425,7 @@ static void qtnf_pcie_remove(struct pci_dev *dev)
	netif_napi_del(&bus->mux_napi);
	destroy_workqueue(priv->workqueue);
	tasklet_kill(&priv->reclaim_tq);
	free_netdev(bus->mux_dev);

	qtnf_pcie_free_shm_ipc(priv);
	qtnf_debugfs_remove(bus);
+3 −3
Original line number Diff line number Diff line
@@ -761,12 +761,12 @@ static int qtnf_pcie_pearl_rx_poll(struct napi_struct *napi, int budget)
				napi_gro_receive(napi, skb);
			} else {
				pr_debug("drop untagged skb\n");
				bus->mux_dev.stats.rx_dropped++;
				bus->mux_dev->stats.rx_dropped++;
				dev_kfree_skb_any(skb);
			}
		} else {
			if (skb) {
				bus->mux_dev.stats.rx_dropped++;
				bus->mux_dev->stats.rx_dropped++;
				dev_kfree_skb_any(skb);
			}
		}
@@ -1146,7 +1146,7 @@ static int qtnf_pcie_pearl_probe(struct qtnf_bus *bus, unsigned int tx_bd_size,
	}

	tasklet_setup(&ps->base.reclaim_tq, qtnf_pearl_reclaim_tasklet_fn);
	netif_napi_add_weight(&bus->mux_dev, &bus->mux_napi,
	netif_napi_add_weight(bus->mux_dev, &bus->mux_napi,
			      qtnf_pcie_pearl_rx_poll, 10);

	ipc_int.fn = qtnf_pcie_pearl_ipc_gen_ep_int;
+3 −3
Original line number Diff line number Diff line
@@ -667,12 +667,12 @@ static int qtnf_topaz_rx_poll(struct napi_struct *napi, int budget)
				netif_receive_skb(skb);
			} else {
				pr_debug("drop untagged skb\n");
				bus->mux_dev.stats.rx_dropped++;
				bus->mux_dev->stats.rx_dropped++;
				dev_kfree_skb_any(skb);
			}
		} else {
			if (skb) {
				bus->mux_dev.stats.rx_dropped++;
				bus->mux_dev->stats.rx_dropped++;
				dev_kfree_skb_any(skb);
			}
		}
@@ -1159,7 +1159,7 @@ static int qtnf_pcie_topaz_probe(struct qtnf_bus *bus,
	}

	tasklet_setup(&ts->base.reclaim_tq, qtnf_reclaim_tasklet_fn);
	netif_napi_add_weight(&bus->mux_dev, &bus->mux_napi,
	netif_napi_add_weight(bus->mux_dev, &bus->mux_napi,
			      qtnf_topaz_rx_poll, 10);

	ipc_int.fn = qtnf_topaz_ipc_gen_ep_int;