Blob Blame History Raw
From: Niklas Schnelle <schnelle@linux.ibm.com>
Date: Fri, 3 Sep 2021 18:27:01 +0200
Subject: s390/pci: fix clp_get_state() handling of -ENODEV
Git-commit: ebd9cc6593691e6bc8526e368cedbdfc8034f403
Patch-mainline: v5.15-rc1
References: jsc#PED-592

With commit cc049eecfb7a ("s390/pci: simplify CLP List PCI handling")
clp_get_state() was changed to make use of the new clp_find_pci() helper
function to query a specific function. This however returns -ENODEV when
the device is not found at all and this error was passed to the caller.
It was missed however that the callers actually expect a success return
from clp_get_state() if the device is gone.

Fix this by handling the -ENODEV return of clp_find_pci() explicitly in
clp_get_state() returning success and setting the state parameter to
ZPCI_FN_STATE_RESERVED matching the design concept that a PCI function
that disappeared must have been resverved elsewhere. For all other error
returns continue to just pass them on to the caller.

Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>
Fixes: cc049eecfb7a ("s390/pci: simplify CLP List PCI handling")
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Acked-by: Petr Tesarik <ptesarik@suse.com>
---
 arch/s390/pci/pci_clp.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

--- a/arch/s390/pci/pci_clp.c
+++ b/arch/s390/pci/pci_clp.c
@@ -449,14 +449,17 @@ int clp_get_state(u32 fid, enum zpci_sta
 	struct clp_fh_list_entry entry;
 	int rc;
 
-	*state = ZPCI_FN_STATE_RESERVED;
 	rrb = clp_alloc_block(GFP_ATOMIC);
 	if (!rrb)
 		return -ENOMEM;
 
 	rc = clp_find_pci(rrb, fid, &entry);
-	if (!rc)
+	if (!rc) {
 		*state = entry.config_state;
+	} else if (rc == -ENODEV) {
+		*state = ZPCI_FN_STATE_RESERVED;
+		rc = 0;
+	}
 
 	clp_free_block(rrb);
 	return rc;