linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dpc.c: fix missing return value check of pci_find_ext_capability()
@ 2018-08-17  8:17 Jiecheng Wu
  2018-08-17 10:55 ` poza
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jiecheng Wu @ 2018-08-17  8:17 UTC (permalink / raw)
  To: linux-pci

Function dpc_probe() defined in drivers/pci/pcie/dpc.c calls pci_find_ext_capability(). Function pci_find_ext_capability() returns the address of the requested extended capability structure within the device's PCI configuration space or 0 if the device does not support it. The return value of this function should be checked against 0.
---
 drivers/pci/pcie/dpc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/pci/pcie/dpc.c b/drivers/pci/pcie/dpc.c
index f03279f..30ff550 100644
--- a/drivers/pci/pcie/dpc.c
+++ b/drivers/pci/pcie/dpc.c
@@ -226,6 +226,8 @@ static int dpc_probe(struct pcie_device *dev)
 		return -ENOMEM;
 
 	dpc->cap_pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_DPC);
+	if (!dpc->cap_pos)
+		return -ENODEV;
 	dpc->dev = dev;
 	set_service_data(dev, dpc);
 
-- 
2.6.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] dpc.c: fix missing return value check of pci_find_ext_capability()
  2018-08-17  8:17 [PATCH] dpc.c: fix missing return value check of pci_find_ext_capability() Jiecheng Wu
@ 2018-08-17 10:55 ` poza
  2018-08-17 14:03 ` Keith Busch
  2018-09-12 20:51 ` Bjorn Helgaas
  2 siblings, 0 replies; 4+ messages in thread
From: poza @ 2018-08-17 10:55 UTC (permalink / raw)
  To: Jiecheng Wu; +Cc: linux-pci, linux-pci-owner

On 2018-08-17 13:47, Jiecheng Wu wrote:
> Function dpc_probe() defined in drivers/pci/pcie/dpc.c calls
> pci_find_ext_capability(). Function pci_find_ext_capability() returns
> the address of the requested extended capability structure within the
> device's PCI configuration space or 0 if the device does not support
> it. The return value of this function should be checked against 0.
> ---
>  drivers/pci/pcie/dpc.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/pci/pcie/dpc.c b/drivers/pci/pcie/dpc.c
> index f03279f..30ff550 100644
> --- a/drivers/pci/pcie/dpc.c
> +++ b/drivers/pci/pcie/dpc.c
> @@ -226,6 +226,8 @@ static int dpc_probe(struct pcie_device *dev)
>  		return -ENOMEM;
> 
>  	dpc->cap_pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_DPC);
> +	if (!dpc->cap_pos)
> +		return -ENODEV;
nitpick: space here
>  	dpc->dev = dev;
>  	set_service_data(dev, dpc);

looks ok to me otherwise.

Regards,
Oza.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] dpc.c: fix missing return value check of pci_find_ext_capability()
  2018-08-17  8:17 [PATCH] dpc.c: fix missing return value check of pci_find_ext_capability() Jiecheng Wu
  2018-08-17 10:55 ` poza
@ 2018-08-17 14:03 ` Keith Busch
  2018-09-12 20:51 ` Bjorn Helgaas
  2 siblings, 0 replies; 4+ messages in thread
From: Keith Busch @ 2018-08-17 14:03 UTC (permalink / raw)
  To: Jiecheng Wu; +Cc: linux-pci

On Fri, Aug 17, 2018 at 04:17:19PM +0800, Jiecheng Wu wrote:
> Function dpc_probe() defined in drivers/pci/pcie/dpc.c calls
> pci_find_ext_capability(). Function pci_find_ext_capability() returns
> the address of the requested extended capability structure within the
> device's PCI configuration space or 0 if the device does not support
> it. The return value of this function should be checked against 0.

dpc_probe will not get called if the capability doesn't exist. The
capability existing is the criteria for PCIE_PORT_SERVICE_DPC flag,
which is required to call dpc_probe.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] dpc.c: fix missing return value check of pci_find_ext_capability()
  2018-08-17  8:17 [PATCH] dpc.c: fix missing return value check of pci_find_ext_capability() Jiecheng Wu
  2018-08-17 10:55 ` poza
  2018-08-17 14:03 ` Keith Busch
@ 2018-09-12 20:51 ` Bjorn Helgaas
  2 siblings, 0 replies; 4+ messages in thread
From: Bjorn Helgaas @ 2018-09-12 20:51 UTC (permalink / raw)
  To: Jiecheng Wu; +Cc: linux-pci, Keith Busch, Sinan Kaya, Oza Pawandeep

[+cc Keith, Sinan, Oza]

Please run "git log --oneline drivers/pci/pcie/dpc.c" and make your
subject match the existing style.

Also, please run "scripts/get_maintainer.pl -f drivers/pci/pcie/dpc.c" and 
cc people who seem interested in the file.

On Fri, Aug 17, 2018 at 04:17:19PM +0800, Jiecheng Wu wrote:
> Function dpc_probe() defined in drivers/pci/pcie/dpc.c calls pci_find_ext_capability(). Function pci_find_ext_capability() returns the address of the requested extended capability structure within the device's PCI configuration space or 0 if the device does not support it. The return value of this function should be checked against 0.

Needs a signed-off-by before I can apply it.  See
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst#n416

> ---
>  drivers/pci/pcie/dpc.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/pci/pcie/dpc.c b/drivers/pci/pcie/dpc.c
> index f03279f..30ff550 100644
> --- a/drivers/pci/pcie/dpc.c
> +++ b/drivers/pci/pcie/dpc.c
> @@ -226,6 +226,8 @@ static int dpc_probe(struct pcie_device *dev)
>  		return -ENOMEM;
>  
>  	dpc->cap_pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_DPC);
> +	if (!dpc->cap_pos)
> +		return -ENODEV;

Keith is right that we shouldn't get here if there's no DPC
capability.  But it's a pain for readers to verify that because that
check is buried in the portdrv driver, so I'm not opposed to adding a
check here.

If we do add a check, I would move the pci_find_ext_capability() and
the check up above the devm_kzalloc().  I know devm will take care of
the cleanup, but I think it's better style to check for things that
require no cleanup first, before doing the things that do require
cleanup.

>  	dpc->dev = dev;
>  	set_service_data(dev, dpc);
>  
> -- 
> 2.6.4
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-09-13  1:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-17  8:17 [PATCH] dpc.c: fix missing return value check of pci_find_ext_capability() Jiecheng Wu
2018-08-17 10:55 ` poza
2018-08-17 14:03 ` Keith Busch
2018-09-12 20:51 ` Bjorn Helgaas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).