return 0;
 }
 
+void psp_ta_free_shared_buf(struct ta_mem_context *mem_ctx)
+{
+       amdgpu_bo_free_kernel(&mem_ctx->shared_bo, &mem_ctx->shared_mc_addr,
+                             &mem_ctx->shared_buf);
+}
+
 static void psp_free_shared_bufs(struct psp_context *psp)
 {
        void *tmr_buf;
                                      &mem_ctx->shared_buf);
 }
 
-void psp_ta_free_shared_buf(struct ta_mem_context *mem_ctx)
-{
-       amdgpu_bo_free_kernel(&mem_ctx->shared_bo, &mem_ctx->shared_mc_addr,
-                             &mem_ctx->shared_buf);
-}
-
 static void psp_prep_ta_invoke_indirect_cmd_buf(struct psp_gfx_cmd_resp *cmd,
                                       uint32_t ta_cmd_id,
                                       struct ta_context *context)
 
        ret = psp_load_non_psp_fw(psp);
        if (ret)
-               goto failed;
+               goto failed1;
 
        ret = psp_asd_initialize(psp);
        if (ret) {
                DRM_ERROR("PSP load asd failed!\n");
-               return ret;
+               goto failed1;
        }
 
        ret = psp_rl_load(adev);
        if (ret) {
                DRM_ERROR("PSP load RL failed!\n");
-               return ret;
+               goto failed1;
        }
 
        if (amdgpu_sriov_vf(adev) && amdgpu_in_reset(adev)) {
 
        return 0;
 
+failed1:
+       psp_free_shared_bufs(psp);
 failed:
        /*
         * all cleanup jobs (xgmi terminate, ras terminate,
         * ring destroy, cmd/fence/fw buffers destory,
         * psp->cmd destory) are delayed to psp_hw_fini
         */
+       psp_ring_destroy(psp, PSP_RING_TYPE__KM);
        return ret;
 }