diff --git a/src/i965_drv_video.c b/src/i965_drv_video.c
index 7e3cef9..e00574f 100644
--- a/src/i965_drv_video.c
+++ b/src/i965_drv_video.c
@@ -2601,40 +2601,37 @@ i965_UnlockSurface(
     struct object_surface *obj_surface = NULL;
 
     obj_surface = SURFACE(surface);
+    if (!obj_surface)
+        return VA_STATUS_ERROR_INVALID_SURFACE;
 
-    if (obj_surface == NULL) {
-        vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;   // Surface is absent
-        goto error;
-    }
     if (obj_surface->locked_image_id == VA_INVALID_ID) {
         vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;   // Surface is not locked
-        goto error;
+        goto end;
     }
 
     locked_img = IMAGE(obj_surface->locked_image_id);
     if (locked_img == NULL || (locked_img->image.image_id == VA_INVALID_ID)) {
         // Work image was deallocated before i965_UnlockSurface()
-        vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
-        goto error;
+        vaStatus = VA_STATUS_END_INVALID_PARAMETER;
+        goto end;
     }
 
     vaStatus = i965_UnmapBuffer(
         ctx,
         locked_img->image.buf);
     if (vaStatus != VA_STATUS_SUCCESS) {
-        goto error;
+        goto end;
     }
 
     vaStatus = i965_DestroyImage(
         ctx,
         locked_img->image.image_id);
     if (vaStatus != VA_STATUS_SUCCESS) {
-        goto error;
+        goto end;
     }
 
+ end:
     locked_img->image.image_id = VA_INVALID_ID;
-
- error:
     return vaStatus;
 }
 
