Skip to content

Commit 0e1a4d4

Browse files
leitaokuba-moo
authored andcommitted
crypto: caam: Unembed net_dev structure in dpaa2
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_devices from struct dpaa2_caam_priv_per_cpu by converting them into pointers, and allocating them dynamically. Use the leverage alloc_netdev_dummy() to allocate the net_device object at dpaa2_dpseci_setup(). The free of the device occurs at dpaa2_dpseci_disable(). Link: https://lore.kernel.org/all/[email protected]/ [1] Signed-off-by: Breno Leitao <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 82c81e7 commit 0e1a4d4

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

drivers/crypto/caam/caamalg_qi2.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4990,11 +4990,23 @@ static int dpaa2_dpseci_congestion_setup(struct dpaa2_caam_priv *priv,
49904990
return err;
49914991
}
49924992

4993+
static void free_dpaa2_pcpu_netdev(struct dpaa2_caam_priv *priv, const cpumask_t *cpus)
4994+
{
4995+
struct dpaa2_caam_priv_per_cpu *ppriv;
4996+
int i;
4997+
4998+
for_each_cpu(i, cpus) {
4999+
ppriv = per_cpu_ptr(priv->ppriv, i);
5000+
free_netdev(ppriv->net_dev);
5001+
}
5002+
}
5003+
49935004
static int __cold dpaa2_dpseci_setup(struct fsl_mc_device *ls_dev)
49945005
{
49955006
struct device *dev = &ls_dev->dev;
49965007
struct dpaa2_caam_priv *priv;
49975008
struct dpaa2_caam_priv_per_cpu *ppriv;
5009+
cpumask_t clean_mask;
49985010
int err, cpu;
49995011
u8 i;
50005012

@@ -5073,6 +5085,7 @@ static int __cold dpaa2_dpseci_setup(struct fsl_mc_device *ls_dev)
50735085
}
50745086
}
50755087

5088+
cpumask_clear(&clean_mask);
50765089
i = 0;
50775090
for_each_online_cpu(cpu) {
50785091
u8 j;
@@ -5096,15 +5109,23 @@ static int __cold dpaa2_dpseci_setup(struct fsl_mc_device *ls_dev)
50965109
priv->rx_queue_attr[j].fqid,
50975110
priv->tx_queue_attr[j].fqid);
50985111

5099-
ppriv->net_dev.dev = *dev;
5100-
INIT_LIST_HEAD(&ppriv->net_dev.napi_list);
5101-
netif_napi_add_tx_weight(&ppriv->net_dev, &ppriv->napi,
5112+
ppriv->net_dev = alloc_netdev_dummy(0);
5113+
if (!ppriv->net_dev) {
5114+
err = -ENOMEM;
5115+
goto err_alloc_netdev;
5116+
}
5117+
cpumask_set_cpu(cpu, &clean_mask);
5118+
ppriv->net_dev->dev = *dev;
5119+
5120+
netif_napi_add_tx_weight(ppriv->net_dev, &ppriv->napi,
51025121
dpaa2_dpseci_poll,
51035122
DPAA2_CAAM_NAPI_WEIGHT);
51045123
}
51055124

51065125
return 0;
51075126

5127+
err_alloc_netdev:
5128+
free_dpaa2_pcpu_netdev(priv, &clean_mask);
51085129
err_get_rx_queue:
51095130
dpaa2_dpseci_congestion_free(priv);
51105131
err_get_vers:
@@ -5153,6 +5174,7 @@ static int __cold dpaa2_dpseci_disable(struct dpaa2_caam_priv *priv)
51535174
ppriv = per_cpu_ptr(priv->ppriv, i);
51545175
napi_disable(&ppriv->napi);
51555176
netif_napi_del(&ppriv->napi);
5177+
free_netdev(ppriv->net_dev);
51565178
}
51575179

51585180
return 0;

drivers/crypto/caam/caamalg_qi2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ struct dpaa2_caam_priv {
8181
*/
8282
struct dpaa2_caam_priv_per_cpu {
8383
struct napi_struct napi;
84-
struct net_device net_dev;
84+
struct net_device *net_dev;
8585
int req_fqid;
8686
int rsp_fqid;
8787
int prio;

0 commit comments

Comments
 (0)