[PATCH v9 03/13] virt: coco: tsm: Complete PCI registration before publishing the device

Xu Yilun yilun.xu at linux.intel.com
Tue Nov 17 23:11:35 PST 2026


>  drivers/virt/coco/tsm-core.c | 35 +++++++++++++----------------------
>  1 file changed, 13 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/virt/coco/tsm-core.c b/drivers/virt/coco/tsm-core.c
> index 57db3f14cf46..181d6114086f 100644
> --- a/drivers/virt/coco/tsm-core.c
> +++ b/drivers/virt/coco/tsm-core.c
> @@ -56,24 +56,6 @@ static struct tsm_dev *alloc_tsm_dev(struct device *parent)
>  	return no_free_ptr(tsm_dev);
>  }
>  
> -static int __tsm_register(struct tsm_dev *tsm_dev, struct pci_tsm_ops *pci_ops)
> -{
> -	int rc;
> -
> -	tsm_dev->pci_ops = pci_ops;
> -	rc = pci_tsm_register(tsm_dev);
> -	if (rc) {
> -		tsm_dev->pci_ops = NULL;
> -		dev_err(tsm_dev->dev.parent,
> -			"PCI/TSM registration failure: %d\n", rc);
> -		return rc;
> -	}
> -
> -	/* Notify TSM userspace that PCI/TSM operations are now possible */
> -	kobject_uevent(&tsm_dev->dev.kobj, KOBJ_CHANGE);
> -	return 0;
> -}
> -
>  struct tsm_dev *tsm_register(struct device *parent, struct pci_tsm_ops *pci_ops)
>  {
>  	struct tsm_dev *tsm_dev __free(put_tsm_dev) = alloc_tsm_dev(parent);
> @@ -91,15 +73,24 @@ struct tsm_dev *tsm_register(struct device *parent, struct pci_tsm_ops *pci_ops)
>  	if (rc)
>  		return ERR_PTR(rc);
>  
> -	rc = device_add(dev);
> -	if (rc)
> +	/* Complete PCI registration before exposing the TSM to class lookup. */
> +	tsm_dev->pci_ops = pci_ops;
> +	rc = pci_tsm_register(tsm_dev);

Ah, sorry. I see you've open-coded it.

I think let's move all tsm_register() side change in this patch. That
saves much intermediate change.

> +	if (rc) {
> +		tsm_dev->pci_ops = NULL;

Besides this unnecessary nullification, others are good to me.

As mentioned, we've done several rounds of detailed reviews for this
early publishing problem. I think it's time to split Patch 1,2,3 out
for merging.

> +		dev_err(parent, "PCI/TSM registration failure: %d\n", rc);
>  		return ERR_PTR(rc);
> +	}
>  
> -	rc = __tsm_register(tsm_dev, pci_ops);
> +	rc = device_add(dev);
>  	if (rc) {
> -		device_del(dev);
> +		pci_tsm_unregister(tsm_dev);
>  		return ERR_PTR(rc);
>  	}
> +
> +	/* Notify TSM userspace that PCI/TSM operations are now possible. */
> +	kobject_uevent(&dev->kobj, KOBJ_CHANGE);
> +
>  	return no_free_ptr(tsm_dev);
>  }
>  EXPORT_SYMBOL_GPL(tsm_register);
> -- 
> 2.43.0
> 



More information about the linux-arm-kernel mailing list