diff --git a/lustre/obdfilter/filter.c b/lustre/obdfilter/filter.c
index 3dea57cc87c6fc2455b6b6b38385f2bda7ad7112..765b748e0931a9fdd17fd82dc5486e52d8aef56b 100644
--- a/lustre/obdfilter/filter.c
+++ b/lustre/obdfilter/filter.c
@@ -2010,19 +2010,22 @@ static int filter_llog_finish(struct obd_device *obd, int count)
                         ctxt->loc_imp = NULL;
                 }
                 mutex_up(&ctxt->loc_sem);
-                rc = llog_cleanup(ctxt);
         }
-        ctxt = llog_get_context(obd, LLOG_SIZE_ORIG_CTXT);
-        if (ctxt)
-                rc2 = llog_cleanup(ctxt);
-        if (!rc)
-                rc = rc2;
 
         if (filter->fo_lcm) {
                 llog_recov_thread_fini(filter->fo_lcm, obd->obd_force);
                 filter->fo_lcm = NULL;
         }
 
+        if (ctxt)
+                rc = llog_cleanup(ctxt);
+
+        ctxt = llog_get_context(obd, LLOG_SIZE_ORIG_CTXT);
+        if (ctxt)
+                rc2 = llog_cleanup(ctxt);
+        if (!rc)
+                rc = rc2;
+
         RETURN(rc);
 }