[PATCH v2 2/3] PCI: Provide lock guard for pci_rescan_remove_lock

Benjamin Block posted 3 patches 3 weeks, 6 days ago
[PATCH v2 2/3] PCI: Provide lock guard for pci_rescan_remove_lock
Posted by Benjamin Block 3 weeks, 6 days ago
Make it possible to use guard() or scoped_guard() to lock, and
automatically unlock `pci_rescan_remove_lock`.

Since the actual mutex `pci_rescan_remove_lock` is always supposed to be
taken and released using the functions pci_lock_rescan_remove() and
pci_unlock_rescan_remove() it is not possible to simply use the already
existing guards for `struct mutex`. Instead define a new guard
`pci_rescan_remove` that will also call the functions in question, but
is usable via guard() or scoped_guard().

Signed-off-by: Benjamin Block <bblock@linux.ibm.com>
---
 include/linux/pci.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/pci.h b/include/linux/pci.h
index fd7a962a64ef..4c41b5a2c90a 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -41,6 +41,7 @@
 #include <linux/msi_api.h>
 #include <linux/mutex.h>
 #include <uapi/linux/pci.h>
+#include <linux/cleanup.h>
 
 #include <linux/pci_ids.h>
 
@@ -1537,6 +1538,8 @@ unsigned int pci_rescan_bus(struct pci_bus *bus);
 extern struct mutex pci_rescan_remove_lock;
 void pci_lock_rescan_remove(void);
 void pci_unlock_rescan_remove(void);
+DEFINE_LOCK_GUARD_0(pci_rescan_remove, pci_lock_rescan_remove(),
+		    pci_unlock_rescan_remove());
 
 /* Vital Product Data routines */
 ssize_t pci_read_vpd(struct pci_dev *dev, loff_t pos, size_t count, void *buf);
-- 
2.53.0
Re: [PATCH v2 2/3] PCI: Provide lock guard for pci_rescan_remove_lock
Posted by Niklas Schnelle 3 weeks, 5 days ago
On Wed, 2026-03-11 at 14:27 +0100, Benjamin Block wrote:
> Make it possible to use guard() or scoped_guard() to lock, and
> automatically unlock `pci_rescan_remove_lock`.
> 
> Since the actual mutex `pci_rescan_remove_lock` is always supposed to be
> taken and released using the functions pci_lock_rescan_remove() and
> pci_unlock_rescan_remove() it is not possible to simply use the already
> existing guards for `struct mutex`. Instead define a new guard
> `pci_rescan_remove` that will also call the functions in question, but
> is usable via guard() or scoped_guard().
> 
> Signed-off-by: Benjamin Block <bblock@linux.ibm.com>
> ---
>  include/linux/pci.h | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index fd7a962a64ef..4c41b5a2c90a 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -41,6 +41,7 @@
>  #include <linux/msi_api.h>
>  #include <linux/mutex.h>
>  #include <uapi/linux/pci.h>
> +#include <linux/cleanup.h>
>  
>  #include <linux/pci_ids.h>
>  
> @@ -1537,6 +1538,8 @@ unsigned int pci_rescan_bus(struct pci_bus *bus);
>  extern struct mutex pci_rescan_remove_lock;
>  void pci_lock_rescan_remove(void);
>  void pci_unlock_rescan_remove(void);
> +DEFINE_LOCK_GUARD_0(pci_rescan_remove, pci_lock_rescan_remove(),
> +		    pci_unlock_rescan_remove());
>  
>  /* Vital Product Data routines */
>  ssize_t pci_read_vpd(struct pci_dev *dev, loff_t pos, size_t count, void *buf);

Looks good to me. Thank you.

Reviewed-by: Niklas Schnelle <schnelle@linux.ibm.com>
Re: [PATCH v2 2/3] PCI: Provide lock guard for pci_rescan_remove_lock
Posted by Benjamin Block 3 weeks, 4 days ago
On Thu, Mar 12, 2026 at 08:44:02PM +0100, Niklas Schnelle wrote:
> On Wed, 2026-03-11 at 14:27 +0100, Benjamin Block wrote:
> > Make it possible to use guard() or scoped_guard() to lock, and
> > automatically unlock `pci_rescan_remove_lock`.
> > 
> > Since the actual mutex `pci_rescan_remove_lock` is always supposed to be
> > taken and released using the functions pci_lock_rescan_remove() and
> > pci_unlock_rescan_remove() it is not possible to simply use the already
> > existing guards for `struct mutex`. Instead define a new guard
> > `pci_rescan_remove` that will also call the functions in question, but
> > is usable via guard() or scoped_guard().
> > 
> > Signed-off-by: Benjamin Block <bblock@linux.ibm.com>
> > ---
> >  include/linux/pci.h | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
--8<--
> 
> Looks good to me. Thank you.
> 
> Reviewed-by: Niklas Schnelle <schnelle@linux.ibm.com>

Thanks.

-- 
Best Regards, Benjamin Block        /        Linux on IBM Z Kernel Development
IBM Deutschland Research & Development GmbH    /   https://www.ibm.com/privacy
Vors. Aufs.-R.: Wolfgang Wendt         /        Geschäftsführung: David Faller
Sitz der Ges.: Ehningen     /     Registergericht: AmtsG Stuttgart, HRB 243294