[PATCH v3 1/6] genirq/msi: Add cleanup guard define for msi_lock_descs()/msi_unlock_descs()

Frank Li posted 6 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH v3 1/6] genirq/msi: Add cleanup guard define for msi_lock_descs()/msi_unlock_descs()
Posted by Frank Li 1 month, 1 week ago
Add a cleanup DEFINE_GUARD macro for msi_lock_descs() and
msi_unlock_descs() to simplify lock and unlock operations in error path.

Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
 include/linux/msi.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/msi.h b/include/linux/msi.h
index b10093c4d00ea..0b6cb7f303887 100644
--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -228,6 +228,8 @@ int msi_setup_device_data(struct device *dev);
 void msi_lock_descs(struct device *dev);
 void msi_unlock_descs(struct device *dev);
 
+DEFINE_GUARD(msi_descs, struct device *, msi_lock_descs(_T), msi_unlock_descs(_T))
+
 struct msi_desc *msi_domain_first_desc(struct device *dev, unsigned int domid,
 				       enum msi_desc_filter filter);
 

-- 
2.34.1
Re: [PATCH v3 1/6] genirq/msi: Add cleanup guard define for msi_lock_descs()/msi_unlock_descs()
Posted by Thomas Gleixner 1 month, 1 week ago
On Tue, Oct 15 2024 at 18:07, Frank Li wrote:

> Add a cleanup DEFINE_GUARD macro for msi_lock_descs() and
> msi_unlock_descs() to simplify lock and unlock operations in error
> path.

What for?

Thanks,

        tglx
Re: [PATCH v3 1/6] genirq/msi: Add cleanup guard define for msi_lock_descs()/msi_unlock_descs()
Posted by Frank Li 1 month, 1 week ago
On Wed, Oct 16, 2024 at 06:21:50PM +0200, Thomas Gleixner wrote:
> On Tue, Oct 15 2024 at 18:07, Frank Li wrote:
>
> > Add a cleanup DEFINE_GUARD macro for msi_lock_descs() and
> > msi_unlock_descs() to simplify lock and unlock operations in error
> > path.
>
> What for?

See [PATCH v3 3/6] PCI: endpoint: Add RC-to-EP doorbell support using platform MSI controller

scoped_guard(msi_descs, dev)
	msi_for_each_desc(desc, dev, MSI_DESC_ALL) {
		...
		if (...)
			goto ...
	}

So cleanup can simplify unlock at error branch.

Frank

>
> Thanks,
>
>         tglx
Re: [PATCH v3 1/6] genirq/msi: Add cleanup guard define for msi_lock_descs()/msi_unlock_descs()
Posted by Damien Le Moal 1 month, 1 week ago
On 10/16/24 7:07 AM, Frank Li wrote:
> Add a cleanup DEFINE_GUARD macro for msi_lock_descs() and
> msi_unlock_descs() to simplify lock and unlock operations in error path.
> 
> Signed-off-by: Frank Li <Frank.Li@nxp.com>
> ---
>  include/linux/msi.h | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/include/linux/msi.h b/include/linux/msi.h
> index b10093c4d00ea..0b6cb7f303887 100644
> --- a/include/linux/msi.h
> +++ b/include/linux/msi.h
> @@ -228,6 +228,8 @@ int msi_setup_device_data(struct device *dev);
>  void msi_lock_descs(struct device *dev);
>  void msi_unlock_descs(struct device *dev);
>  
> +DEFINE_GUARD(msi_descs, struct device *, msi_lock_descs(_T), msi_unlock_descs(_T))
> +

This belongs with patch 3 since it is first used there.

>  struct msi_desc *msi_domain_first_desc(struct device *dev, unsigned int domid,
>  				       enum msi_desc_filter filter);

-- 
Damien Le Moal
Western Digital Research