Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
                p9_client_clunk(fid);
                return ERR_CAST(inode);
        }
-       v9fs_fid_add(dentry, fid);
        /*
         * If we had a rename on the server and a parallel lookup
         * for the new name, then make sure we instantiate with
         * k/b.
         */
        res = d_materialise_unique(dentry, inode);
-       if (IS_ERR(res))
+       if (!res)
+               v9fs_fid_add(dentry, fid);
+       else if (!IS_ERR(res))
+               v9fs_fid_add(res, fid);
+       else
                p9_client_clunk(fid);
        return res;
 }