]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
powerpc/powernv: Fix pci-cxl.c build when CONFIG_MODULES=n
authorIan Munsie <imunsie@au1.ibm.com>
Tue, 19 Jul 2016 02:33:35 +0000 (12:33 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 19 Jul 2016 10:12:28 +0000 (20:12 +1000)
pnv_cxl_enable_phb_kernel_api() grabs a reference to the cxl module to
prevent it from being unloaded after the PHB has been switched to CX4
mode. This breaks the build when CONFIG_MODULES=n as module_mutex
doesn't exist.

However, if we don't have modules, we don't need to protect against the
case of the cxl module being unloaded. As such, split the relevant code
out into a function surrounded with #if IS_MODULE(CXL) so we don't try
to compile it if cxl isn't being compiled as a module.

Fixes: 5918dbc9b4ec ("powerpc/powernv: Add support for the cxl kernel api on the real phb")
Reported-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Ian Munsie <imunsie@au1.ibm.com>
Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/platforms/powernv/pci-cxl.c

index 3f342077628b87d96e8d27c2afb78a01d94b259a..1349a099c74c64f9fbbf9cd5faf288112c13d298 100644 (file)
@@ -166,6 +166,28 @@ int pnv_cxl_ioda_msi_setup(struct pci_dev *dev, unsigned int hwirq,
 }
 EXPORT_SYMBOL(pnv_cxl_ioda_msi_setup);
 
+#if IS_MODULE(CONFIG_CXL)
+static inline int get_cxl_module(void)
+{
+       struct module *cxl_module;
+
+       mutex_lock(&module_mutex);
+
+       cxl_module = find_module("cxl");
+       if (cxl_module)
+               __module_get(cxl_module);
+
+       mutex_unlock(&module_mutex);
+
+       if (!cxl_module)
+               return -ENODEV;
+
+       return 0;
+}
+#else
+static inline int get_cxl_module(void) { return 0; }
+#endif
+
 /*
  * Sets flags and switches the controller ops to enable the cxl kernel api.
  * Originally the cxl kernel API operated on a virtual PHB, but certain cards
@@ -175,7 +197,7 @@ EXPORT_SYMBOL(pnv_cxl_ioda_msi_setup);
 int pnv_cxl_enable_phb_kernel_api(struct pci_controller *hose, bool enable)
 {
        struct pnv_phb *phb = hose->private_data;
-       struct module *cxl_module;
+       int rc;
 
        if (!enable) {
                /*
@@ -194,13 +216,9 @@ int pnv_cxl_enable_phb_kernel_api(struct pci_controller *hose, bool enable)
         * long as we are in this mode (and since we can't safely disable this
         * mode once enabled...).
         */
-       mutex_lock(&module_mutex);
-       cxl_module = find_module("cxl");
-       if (cxl_module)
-               __module_get(cxl_module);
-       mutex_unlock(&module_mutex);
-       if (!cxl_module)
-               return -ENODEV;
+       rc = get_cxl_module();
+       if (rc)
+               return rc;
 
        phb->flags |= PNV_PHB_FLAG_CXL;
        hose->controller_ops = pnv_cxl_cx4_ioda_controller_ops;