diff mbox

cxl: abort cxl_pci_enable_device_hook() if PCI channel is offline

Message ID 1441347624-9787-1-git-send-email-andrew.donnellan@au1.ibm.com (mailing list archive)
State Superseded
Headers show

Commit Message

Andrew Donnellan Sept. 4, 2015, 6:20 a.m. UTC
cxl_pci_enable_device_hook() is called when attempting to enable an AFU
sitting on a vPHB. At present, the state of the underlying CXL card's PCI
channel is only checked when it calls cxl_afu_check_and_enable() at the
very end, after it has already set DMA options and initialised a default
context.

Check the CXL card's link status before setting DMA options or initialising
a default context. If the link is down, print a warning and return
immediately.

Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
---
 drivers/misc/cxl/vphb.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Ian Munsie Sept. 6, 2015, 11:58 p.m. UTC | #1
Excerpts from andrew.donnellan's message of 2015-09-04 16:20:24 +1000:
> +    if (!cxl_adapter_link_ok(afu->adapter))
> +        dev_warn(&dev->dev, "%s: Device link is down, refusing to enable AFU\n", __func__);
> +        return false;

Based on the indentation it looks like you meant to add some curly
brackets here.

-Ian
Andrew Donnellan Sept. 7, 2015, 12:22 a.m. UTC | #2
On 07/09/15 09:58, Ian Munsie wrote:
> Excerpts from andrew.donnellan's message of 2015-09-04 16:20:24 +1000:
>> +    if (!cxl_adapter_link_ok(afu->adapter))
>> +        dev_warn(&dev->dev, "%s: Device link is down, refusing to enable AFU\n", __func__);
>> +        return false;
>
> Based on the indentation it looks like you meant to add some curly
> brackets here.

Indeed I did, and I'd even thought I'd tested it... this is why I 
shouldn't be allowed to submit patches at 4pm on Fridays...

Will submit V2.

(FWIW, I'm a firm believer in braces around single statements in 
conditionals to avoid mistakes like this, but CodingStyle disagrees...)


Andrew
Ian Munsie Sept. 7, 2015, 6:33 a.m. UTC | #3
No worries. I've been caught out by something similar in the past when I
assumed that something like this:

if (foo)
	/*
	 * A big long
	 * multiline
	 * block comment!
	 */
	 do_something()

would surely already have curly brackets around it ;-)

Excerpts from andrew.donnellan's message of 2015-09-07 10:22:31 +1000:
> 
> On 07/09/15 09:58, Ian Munsie wrote:
> > Excerpts from andrew.donnellan's message of 2015-09-04 16:20:24 +1000:
> >> +    if (!cxl_adapter_link_ok(afu->adapter))
> >> +        dev_warn(&dev->dev, "%s: Device link is down, refusing to enable AFU\n", __func__);
> >> +        return false;
> >
> > Based on the indentation it looks like you meant to add some curly
> > brackets here.
> 
> Indeed I did, and I'd even thought I'd tested it... this is why I 
> shouldn't be allowed to submit patches at 4pm on Fridays...
> 
> Will submit V2.
> 
> (FWIW, I'm a firm believer in braces around single statements in 
> conditionals to avoid mistakes like this, but CodingStyle disagrees...)
> 
> 
> Andrew
>
Michael Ellerman Sept. 7, 2015, 8:43 a.m. UTC | #4
On Mon, 2015-09-07 at 16:33 +1000, Ian Munsie wrote:
> No worries. I've been caught out by something similar in the past when I
> assumed that something like this:
> 
> if (foo)
> 	/*
> 	 * A big long
> 	 * multiline
> 	 * block comment!
> 	 */
> 	 do_something()
> 
> would surely already have curly brackets around it ;-)

You guys can do whatever you like for the cxl code.

cheers
diff mbox

Patch

diff --git a/drivers/misc/cxl/vphb.c b/drivers/misc/cxl/vphb.c
index 6dd16a6..1972fb6 100644
--- a/drivers/misc/cxl/vphb.c
+++ b/drivers/misc/cxl/vphb.c
@@ -48,6 +48,11 @@  static bool cxl_pci_enable_device_hook(struct pci_dev *dev)
 
 	phb = pci_bus_to_host(dev->bus);
 	afu = (struct cxl_afu *)phb->private_data;
+
+	if (!cxl_adapter_link_ok(afu->adapter))
+		dev_warn(&dev->dev, "%s: Device link is down, refusing to enable AFU\n", __func__);
+		return false;
+
 	set_dma_ops(&dev->dev, &dma_direct_ops);
 	set_dma_offset(&dev->dev, PAGE_OFFSET);