crypto: qat - fix double release_firmware on error path
authorTadeusz Struk <tadeusz.struk@intel.com>
Fri, 3 Apr 2015 15:41:17 +0000 (08:41 -0700)
committerHerbert Xu <herbert@gondor.apana.org.au>
Tue, 7 Apr 2015 13:34:22 +0000 (21:34 +0800)
release_firmware was called twice on error path causing an Oops.

Reported-by: Ahsan Atta <ahsan.atta@intel.com>
Signed-off-by: Tadeusz Struk <tadeusz.struk@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/qat/qat_common/adf_accel_engine.c
drivers/crypto/qat/qat_common/adf_common_drv.h
drivers/crypto/qat/qat_common/adf_init.c

index 97e8ea5d928c92c62b0523777aabd9f1de5ded91..7f8b66c915ed4bd7341961df49470e55bb767278 100644 (file)
@@ -78,19 +78,22 @@ int adf_ae_fw_load(struct adf_accel_dev *accel_dev)
        return 0;
 
 out_err:
-       release_firmware(loader_data->uof_fw);
+       adf_ae_fw_release(accel_dev);
        return -EFAULT;
 }
 
-int adf_ae_fw_release(struct adf_accel_dev *accel_dev)
+void adf_ae_fw_release(struct adf_accel_dev *accel_dev)
 {
        struct adf_fw_loader_data *loader_data = accel_dev->fw_loader;
 
-       release_firmware(loader_data->uof_fw);
        qat_uclo_del_uof_obj(loader_data->fw_loader);
        qat_hal_deinit(loader_data->fw_loader);
+
+       if (loader_data->uof_fw)
+               release_firmware(loader_data->uof_fw);
+
+       loader_data->uof_fw = NULL;
        loader_data->fw_loader = NULL;
-       return 0;
 }
 
 int adf_ae_start(struct adf_accel_dev *accel_dev)
@@ -165,6 +168,9 @@ int adf_ae_init(struct adf_accel_dev *accel_dev)
 
 int adf_ae_shutdown(struct adf_accel_dev *accel_dev)
 {
+       struct adf_fw_loader_data *loader_data = accel_dev->fw_loader;
+
+       qat_hal_deinit(loader_data->fw_loader);
        kfree(accel_dev->fw_loader);
        accel_dev->fw_loader = NULL;
        return 0;
index a62e485c8786f04a57dfd67ea572b1ca2d8e824e..0666ee6a3360feac17675575d9d44c61b38a190e 100644 (file)
@@ -115,7 +115,7 @@ int adf_dev_restarted_notify(struct adf_accel_dev *accel_dev);
 int adf_ae_init(struct adf_accel_dev *accel_dev);
 int adf_ae_shutdown(struct adf_accel_dev *accel_dev);
 int adf_ae_fw_load(struct adf_accel_dev *accel_dev);
-int adf_ae_fw_release(struct adf_accel_dev *accel_dev);
+void adf_ae_fw_release(struct adf_accel_dev *accel_dev);
 int adf_ae_start(struct adf_accel_dev *accel_dev);
 int adf_ae_stop(struct adf_accel_dev *accel_dev);
 
index da5793b348412050b3f794a6ea15921d7d774c7e..245f43237a2d8b168b034f8a5568753819f027dc 100644 (file)
@@ -160,7 +160,6 @@ int adf_dev_init(struct adf_accel_dev *accel_dev)
        if (adf_ae_fw_load(accel_dev)) {
                dev_err(&GET_DEV(accel_dev),
                        "Failed to load acceleration FW\n");
-               adf_ae_fw_release(accel_dev);
                return -EFAULT;
        }
        set_bit(ADF_STATUS_AE_UCODE_LOADED, &accel_dev->status);
@@ -359,12 +358,8 @@ void adf_dev_shutdown(struct adf_accel_dev *accel_dev)
        }
 
        if (test_bit(ADF_STATUS_AE_UCODE_LOADED, &accel_dev->status)) {
-               if (adf_ae_fw_release(accel_dev))
-                       dev_err(&GET_DEV(accel_dev),
-                               "Failed to release the ucode\n");
-               else
-                       clear_bit(ADF_STATUS_AE_UCODE_LOADED,
-                                 &accel_dev->status);
+               adf_ae_fw_release(accel_dev);
+               clear_bit(ADF_STATUS_AE_UCODE_LOADED, &accel_dev->status);
        }
 
        if (test_bit(ADF_STATUS_AE_INITIALISED, &accel_dev->status)) {