return DC_OK;
 }
 
-static void detach_surfaces_for_stream(
-               struct validate_context *context,
-               const struct resource_pool *pool,
-               const struct dc_stream *dc_stream)
-{
-       int i;
-       struct core_stream *stream = DC_STREAM_TO_CORE(dc_stream);
-
-       for (i = 0; i < pool->pipe_count; i++) {
-               struct pipe_ctx *cur_pipe = &context->res_ctx.pipe_ctx[i];
-               if (cur_pipe->stream == stream) {
-                       cur_pipe->surface = NULL;
-                       cur_pipe->top_pipe = NULL;
-                       cur_pipe->bottom_pipe = NULL;
-               }
-       }
-}
-
 struct pipe_ctx *find_idle_secondary_pipe(
                struct resource_context *res_ctx,
                const struct resource_pool *pool)
        struct core_stream *stream = DC_STREAM_TO_CORE(dc_stream);
 
        for (i = MAX_PIPES - 1; i >= 0; i--) {
+               /* never release the topmost pipe*/
                if (res_ctx->pipe_ctx[i].stream == stream &&
+                               res_ctx->pipe_ctx[i].top_pipe &&
                                !res_ctx->pipe_ctx[i].surface) {
-                       res_ctx->pipe_ctx[i].stream = NULL;
+                       memset(&res_ctx->pipe_ctx[i], 0, sizeof(struct pipe_ctx));
                }
        }
 }
        int i;
        struct pipe_ctx *tail_pipe;
        struct dc_stream_status *stream_status = NULL;
+       struct core_stream *stream = DC_STREAM_TO_CORE(dc_stream);
 
 
        if (surface_count > MAX_SURFACE_NUM) {
        for (i = 0; i < surface_count; i++)
                dc_surface_retain(surfaces[i]);
 
-       detach_surfaces_for_stream(context, pool, dc_stream);
+       /* detach surfaces from pipes */
+       for (i = 0; i < pool->pipe_count; i++)
+               if (context->res_ctx.pipe_ctx[i].stream == stream) {
+                       context->res_ctx.pipe_ctx[i].surface = NULL;
+                       context->res_ctx.pipe_ctx[i].bottom_pipe = NULL;
+               }
 
        /* release existing surfaces*/
        for (i = 0; i < stream_status->surface_count; i++)
        for (i = surface_count; i < stream_status->surface_count; i++)
                stream_status->surfaces[i] = NULL;
 
-       stream_status->surface_count = 0;
-
-       if (surface_count == 0)
-               return true;
-
        tail_pipe = NULL;
        for (i = 0; i < surface_count; i++) {
                struct core_surface *surface = DC_SURFACE_TO_CORE(surfaces[i]);