kref_get(&map->refcount);
 }
 
-static int fastrpc_map_find(struct fastrpc_user *fl, int fd,
+
+static int fastrpc_map_lookup(struct fastrpc_user *fl, int fd,
                            struct fastrpc_map **ppmap)
 {
        struct fastrpc_map *map = NULL;
        mutex_lock(&fl->mutex);
        list_for_each_entry(map, &fl->maps, node) {
                if (map->fd == fd) {
-                       fastrpc_map_get(map);
                        *ppmap = map;
                        mutex_unlock(&fl->mutex);
                        return 0;
        return -ENOENT;
 }
 
+static int fastrpc_map_find(struct fastrpc_user *fl, int fd,
+                           struct fastrpc_map **ppmap)
+{
+       int ret = fastrpc_map_lookup(fl, fd, ppmap);
+
+       if (!ret)
+               fastrpc_map_get(*ppmap);
+
+       return ret;
+}
+
 static void fastrpc_buf_free(struct fastrpc_buf *buf)
 {
        dma_free_coherent(buf->dev, buf->size, buf->virt,
        ctx = container_of(ref, struct fastrpc_invoke_ctx, refcount);
        cctx = ctx->cctx;
 
-       for (i = 0; i < ctx->nscalars; i++)
+       for (i = 0; i < ctx->nbufs; i++)
                fastrpc_map_put(ctx->maps[i]);
 
        if (ctx->buf)
                            u32 kernel)
 {
        struct fastrpc_remote_arg *rpra = ctx->rpra;
-       int i, inbufs;
+       struct fastrpc_user *fl = ctx->fl;
+       struct fastrpc_map *mmap = NULL;
+       struct fastrpc_invoke_buf *list;
+       struct fastrpc_phy_page *pages;
+       u64 *fdlist;
+       int i, inbufs, outbufs, handles;
 
        inbufs = REMOTE_SCALARS_INBUFS(ctx->sc);
+       outbufs = REMOTE_SCALARS_OUTBUFS(ctx->sc);
+       handles = REMOTE_SCALARS_INHANDLES(ctx->sc) + REMOTE_SCALARS_OUTHANDLES(ctx->sc);
+       list = fastrpc_invoke_buf_start(rpra, ctx->nscalars);
+       pages = fastrpc_phy_page_start(list, ctx->nscalars);
+       fdlist = (uint64_t *)(pages + inbufs + outbufs + handles);
 
        for (i = inbufs; i < ctx->nbufs; ++i) {
                if (!ctx->maps[i]) {
                }
        }
 
+       for (i = 0; i < FASTRPC_MAX_FDLIST; i++) {
+               if (!fdlist[i])
+                       break;
+               if (!fastrpc_map_lookup(fl, (int)fdlist[i], &mmap))
+                       fastrpc_map_put(mmap);
+       }
+
        return 0;
 }