On Tue, 2 Jul 2024 11:55:53 -0700 Breno Leitao wrote: > +static void free_caam_qi_pcpu_netdev(const cpumask_t *cpus) > +{ > + struct caam_qi_pcpu_priv *priv; > + int i; > + > + for_each_cpu(i, cpus) { > + priv = per_cpu_ptr(&pcpu_qipriv, i); > + free_netdev(priv->net_dev); > + } > +} > + > int caam_qi_init(struct platform_device *caam_pdev) > { > int err, i; > struct device *ctrldev = &caam_pdev->dev, *qidev; > struct caam_drv_private *ctrlpriv; > const cpumask_t *cpus = qman_affine_cpus(); > + cpumask_t clean_mask; > > ctrlpriv = dev_get_drvdata(ctrldev); > qidev = ctrldev; > @@ -743,6 +756,8 @@ int caam_qi_init(struct platform_device *caam_pdev) > return err; > } > > + cpumask_clear(&clean_mask); > + > /* > * Enable the NAPI contexts on each of the core which has an affine > * portal. > @@ -751,10 +766,16 @@ int caam_qi_init(struct platform_device *caam_pdev) > struct caam_qi_pcpu_priv *priv = per_cpu_ptr(&pcpu_qipriv, i); > struct caam_napi *caam_napi = &priv->caam_napi; > struct napi_struct *irqtask = &caam_napi->irqtask; > - struct net_device *net_dev = &priv->net_dev; > + struct net_device *net_dev; > > + net_dev = alloc_netdev_dummy(0); > + if (!net_dev) { > + err = -ENOMEM; > + goto fail; free_netdev() doesn't take NULL, free_caam_qi_pcpu_netdev() will feed it one if we fail here > + } > + cpumask_set_cpu(i, &clean_mask); > + priv->net_dev = net_dev; > net_dev->dev = *qidev; > - INIT_LIST_HEAD(&net_dev->napi_list); > > netif_napi_add_tx_weight(net_dev, irqtask, caam_qi_poll, > CAAM_NAPI_WEIGHT); > @@ -766,16 +787,22 @@ int caam_qi_init(struct platform_device *caam_pdev) > dma_get_cache_alignment(), 0, NULL); > if (!qi_cache) { > dev_err(qidev, "Can't allocate CAAM cache\n"); > - free_rsp_fqs(); > - return -ENOMEM; > + err = -ENOMEM; > + goto fail2; > } > > caam_debugfs_qi_init(ctrlpriv); > > err = devm_add_action_or_reset(qidev, caam_qi_shutdown, ctrlpriv); > if (err) > - return err; > + goto fail2; > > dev_info(qidev, "Linux CAAM Queue I/F driver initialised\n"); > return 0; > + > +fail2: > + free_rsp_fqs(); > +fail: > + free_caam_qi_pcpu_netdev(&clean_mask);