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

From: Niklas Schnelle

Date: Thu Mar 12 2026 - 15:46:00 EST


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@xxxxxxxxxxxxx>
> ---
> 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@xxxxxxxxxxxxx>