9pfs: misc patches

* Fix an occasional crash when handling 'Twalk' requests.
 
 * Two code cleanup patches.
 -----BEGIN PGP SIGNATURE-----
 
 iQJLBAABCgA1FiEEltjREM96+AhPiFkBNMK1h2Wkc5UFAmEwuKgXHHFlbXVfb3Nz
 QGNydWRlYnl0ZS5jb20ACgkQNMK1h2Wkc5XBexAAzA8h4GhHKGXTMdJj9my94wfr
 qrcAp/ixQLqHwEPGS4HQi4qEvXJmqm/S9Jr5cbTgGdsq5VlmdvdW77HQVCXY/ECL
 h0ZbTYrjA1YGJWa/5TYGdsQhu15b6mplc3g7p35K+ZfwXx80qC/snQqMueX2l2yk
 JpMGMhTHlQTjIk6XYkMSUJ/0q60mgNEiiqpW5l7BnaFn3x5WQxtwUD85DLDBQBLU
 v9xtMYPy0WQ4acnqgY1ZeIRrBGGFLqcZgbaYdp05fYNGSO2yLT8wfVBfYu1FHEsZ
 E5biIqNJAorvWHLeytC8QzIJ+CWKDouZvyK3TFKU4mPEOEjDlrfxXTFT+VZycC/B
 v0RoIf2j5BNp4gVYcVIlrU3gDMr4DaC0gvgelbIe5R9lOg7iQ/TL6weazMabAGgw
 Q8Hqgd6ZPkvbKNzOIE5k7rMdrkoLETbV9FdmQjVa80g0T0veybiaKY4HHiU7QWM8
 NkQShABbi2YHCJIiTtKg3VRh1zCNl0Gch69Pbko4uXpnYLFvGQxMCU8spZ+7da8K
 b9Ya+u0cenCJiE6a5ywJaG8T2qL+wFtouDDBCbO8XiBmp/S6ZKJCA7PvphPXa+/z
 zTgTCZ4Tc76RBKBYxS4+/8Q9oyeGlxlHq2k+Dn3/wA16FkWkjCKFlpQ0jobiX5Ou
 uFPa19Ok9uGAt8oKzfQ=
 =q+nY
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/cschoenebeck/tags/pull-9p-20210902' into staging

9pfs: misc patches

* Fix an occasional crash when handling 'Twalk' requests.

* Two code cleanup patches.

# gpg: Signature made Thu 02 Sep 2021 12:42:32 BST
# gpg:                using RSA key 96D8D110CF7AF8084F88590134C2B58765A47395
# gpg:                issuer "qemu_oss@crudebyte.com"
# gpg: Good signature from "Christian Schoenebeck <qemu_oss@crudebyte.com>" [unknown]
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: ECAB 1A45 4014 1413 BA38  4926 30DB 47C3 A012 D5F4
#      Subkey fingerprint: 96D8 D110 CF7A F808 4F88  5901 34C2 B587 65A4 7395

* remotes/cschoenebeck/tags/pull-9p-20210902:
  9pfs: fix crash in v9fs_walk()
  hw/9pfs: use g_autofree in v9fs_walk() where possible
  hw/9pfs: avoid 'path' copy in v9fs_walk()

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
master
Peter Maydell 2021-09-03 08:27:38 +01:00
commit 8880cc4362
2 changed files with 10 additions and 9 deletions

View File

@ -1703,11 +1703,12 @@ static bool same_stat_id(const struct stat *a, const struct stat *b)
static void coroutine_fn v9fs_walk(void *opaque)
{
int name_idx;
V9fsQID *qids = NULL;
g_autofree V9fsQID *qids = NULL;
int i, err = 0;
V9fsPath dpath, path, *pathes = NULL;
uint16_t nwnames;
struct stat stbuf, fidst, *stbufs = NULL;
struct stat stbuf, fidst;
g_autofree struct stat *stbufs = NULL;
size_t offset = 7;
int32_t fid, newfid;
V9fsString *wnames = NULL;
@ -1787,7 +1788,8 @@ static void coroutine_fn v9fs_walk(void *opaque)
strcmp("..", wnames[name_idx].data))
{
err = s->ops->name_to_path(&s->ctx, &dpath,
wnames[name_idx].data, &path);
wnames[name_idx].data,
&pathes[name_idx]);
if (err < 0) {
err = -errno;
break;
@ -1796,14 +1798,13 @@ static void coroutine_fn v9fs_walk(void *opaque)
err = -EINTR;
break;
}
err = s->ops->lstat(&s->ctx, &path, &stbuf);
err = s->ops->lstat(&s->ctx, &pathes[name_idx], &stbuf);
if (err < 0) {
err = -errno;
break;
}
stbufs[name_idx] = stbuf;
v9fs_path_copy(&dpath, &path);
v9fs_path_copy(&pathes[name_idx], &path);
v9fs_path_copy(&dpath, &pathes[name_idx]);
}
}
});
@ -1872,8 +1873,6 @@ out_nofid:
v9fs_path_free(&pathes[name_idx]);
}
g_free(wnames);
g_free(qids);
g_free(stbufs);
g_free(pathes);
}
}

View File

@ -51,7 +51,9 @@
*/ \
qemu_coroutine_yield(); \
qemu_bh_delete(co_bh); \
code_block; \
do { \
code_block; \
} while (0); \
/* re-enter back to qemu thread */ \
qemu_coroutine_yield(); \
} while (0)