Linux PCI subsystem development
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
Cc: bhelgaas@google.com, linux-pci@vger.kernel.org
Subject: Re: [PATCH] PCI: Add lock  and reference count in pci_get_domain_bus_and_slot()
Date: Wed, 1 Oct 2025 14:25:54 +0300 (EEST)	[thread overview]
Message-ID: <f78ffb8a-0709-6096-87f7-b74bf32aae6a@linux.intel.com> (raw)
In-Reply-To: <20251001043705.263609-1-kaushlendra.kumar@intel.com>

On Wed, 1 Oct 2025, Kaushlendra Kumar wrote:

> Add proper locking and reference counting to pci_get_domain_bus_and_slot

Add () to any function names.

> during PCI device enumeration. The function now holds pci_bus_sem during
> device iteration and properly increments the device reference count
> before returning.

These two sentences duplicate each other. Could you state things just once 
with the more precise explanation that is in the 2nd sentence.

Also, I'd prefer to see the problem described in a paragraph preceeding 
this solution paragraph/sentence.

Fixes tag?

> Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
> ---
>  drivers/pci/search.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/search.c b/drivers/pci/search.c
> index 53840634fbfc..dc49d3db69a4 100644
> --- a/drivers/pci/search.c
> +++ b/drivers/pci/search.c
> @@ -230,12 +230,17 @@ struct pci_dev *pci_get_domain_bus_and_slot(int domain, unsigned int bus,
>  {
>  	struct pci_dev *dev = NULL;
>  
> +	down_read(&pci_bus_sem);

How about using

guard(rwsem_read)(&pci_bus_sem);

?

I think that would look a lot cleaner overall.

>  	for_each_pci_dev(dev) {
>  		if (pci_domain_nr(dev->bus) == domain &&
>  		    (dev->bus->number == bus && dev->devfn == devfn))
> -			return dev;
> +			goto out;
>  	}
> -	return NULL;
> +	dev = NULL;
> + out:
> +	pci_dev_get(dev);

So now you're incrementing the reference count but there's no code in this 
patch to counterdecrement it? Are all callers already decrementing it 
(which leads to underflows w/o this patch)? This needs to be explained in 
the changelog text.

> +	up_read(&pci_bus_sem);
> +	return dev;
>  }
>  EXPORT_SYMBOL(pci_get_domain_bus_and_slot);

-- 
 i.


      reply	other threads:[~2025-10-01 11:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-01  4:37 [PATCH] PCI: Add lock and reference count in pci_get_domain_bus_and_slot() Kaushlendra Kumar
2025-10-01 11:25 ` Ilpo Järvinen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f78ffb8a-0709-6096-87f7-b74bf32aae6a@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=bhelgaas@google.com \
    --cc=kaushlendra.kumar@intel.com \
    --cc=linux-pci@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox