This patch fixes an unused variable warning from the compiler when the
driver is being compiled without PCI support in the kernel.

changes since v1:
- capture the platform_register_driver error code as well
- actually return the (last) error code
- swapped registration to do PCI first as that's just for development
  boards anyway, so in case both are done we want the platform error
  or no error at all if that passes
- also fixes some indentation issue in the affected code

changes since v2:
- handle the situation where both CONFIG_PCI and CONFIG_OF are undefined
  by always returning a -EINVAL error
- only unregister PCI or OF if it was previously successfully registered

changes since v3:
- if *both* PCI and OF are configured, then return success if *either*
  registration was OK, also ensuring exit is called and PCI unregister
  occurs (eventually) if only OF registration fails

Signed-off-by: Pascal van Leeuwen <pvanleeu...@verimatrix.com>
---
 drivers/crypto/inside-secure/safexcel.c | 40 ++++++++++++++++++++++++---------
 1 file changed, 29 insertions(+), 11 deletions(-)

diff --git a/drivers/crypto/inside-secure/safexcel.c 
b/drivers/crypto/inside-secure/safexcel.c
index e12a2a3..5abe8b6 100644
--- a/drivers/crypto/inside-secure/safexcel.c
+++ b/drivers/crypto/inside-secure/safexcel.c
@@ -1501,32 +1501,50 @@ void safexcel_pci_remove(struct pci_dev *pdev)
 };
 #endif
 
-static int __init safexcel_init(void)
-{
-       int rc;
-
+/* Unfortunately, we have to resort to global variables here */
+#if IS_ENABLED(CONFIG_PCI)
+int pcireg_rc = -EINVAL; /* Default safe value */
+#endif
 #if IS_ENABLED(CONFIG_OF)
-               /* Register platform driver */
-               platform_driver_register(&crypto_safexcel);
+int ofreg_rc = -EINVAL; /* Default safe value */
 #endif
 
+static int __init safexcel_init(void)
+{
 #if IS_ENABLED(CONFIG_PCI)
-               /* Register PCI driver */
-               rc = pci_register_driver(&safexcel_pci_driver);
+       /* Register PCI driver */
+       pcireg_rc = pci_register_driver(&safexcel_pci_driver);
 #endif
 
-       return 0;
+#if IS_ENABLED(CONFIG_OF)
+       /* Register platform driver */
+       ofreg_rc = platform_driver_register(&crypto_safexcel);
+ #if IS_ENABLED(CONFIG_PCI)
+       /* Return success if either PCI or OF registered OK */
+       return pcireg_rc ? ofreg_rc : 0;
+ #else
+       return ofreg_rc;
+ #endif
+#else
+ #if IS_ENABLED(CONFIG_PCI)
+       return pcireg_rc;
+ #else
+       return -EINVAL;
+ #endif
+#endif
 }
 
 static void __exit safexcel_exit(void)
 {
 #if IS_ENABLED(CONFIG_OF)
-               /* Unregister platform driver */
+       /* Unregister platform driver */
+       if (!ofreg_rc)
                platform_driver_unregister(&crypto_safexcel);
 #endif
 
 #if IS_ENABLED(CONFIG_PCI)
-               /* Unregister PCI driver if successfully registered before */
+       /* Unregister PCI driver if successfully registered before */
+       if (!pcireg_rc)
                pci_unregister_driver(&safexcel_pci_driver);
 #endif
 }
-- 
1.8.3.1

Reply via email to