Skip to content

Commit 92c4512

Browse files
Vladimir Sementsov-OgievskiyMarkus Armbruster
authored andcommitted
virtio-9p: Use ERRP_GUARD()
If we want to check error after errp-function call, we need to introduce local_err and then propagate it to errp. Instead, use the ERRP_GUARD() macro, benefits are: 1. No need of explicit error_propagate call 2. No need of explicit local_err variable: use errp directly 3. ERRP_GUARD() leaves errp as is if it's not NULL or &error_fatal, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate) If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_GUARD() macro. Otherwise, this info will not be added when errp == &error_fatal (the program will exit prior to the error_append_hint() or error_prepend() call). Fix such a case in v9fs_device_realize_common(). This commit is generated by command sed -n '/^virtio-9p$/,/^$/{s/^F: //p}' MAINTAINERS | \ xargs git ls-files | grep '\.[hc]$' | \ xargs spatch \ --sp-file scripts/coccinelle/errp-guard.cocci \ --macro-file scripts/cocci-macro-file.h \ --in-place --no-show-diff --max-width 80 Reported-by: Kevin Wolf <[email protected]> Reported-by: Greg Kurz <[email protected]> Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]> Acked-by: Greg Kurz <[email protected]> Reviewed-by: Christian Schoenebeck <[email protected]> [Commit message tweaked] Signed-off-by: Markus Armbruster <[email protected]> Message-Id: <[email protected]> [ERRP_AUTO_PROPAGATE() renamed to ERRP_GUARD(), and auto-propagated-errp.cocci to errp-guard.cocci. Commit message tweaked again.]
1 parent 8b4b527 commit 92c4512

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

hw/9pfs/9p-local.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,10 +1479,10 @@ static void error_append_security_model_hint(Error *const *errp)
14791479

14801480
static int local_parse_opts(QemuOpts *opts, FsDriverEntry *fse, Error **errp)
14811481
{
1482+
ERRP_GUARD();
14821483
const char *sec_model = qemu_opt_get(opts, "security_model");
14831484
const char *path = qemu_opt_get(opts, "path");
14841485
const char *multidevs = qemu_opt_get(opts, "multidevs");
1485-
Error *local_err = NULL;
14861486

14871487
if (!sec_model) {
14881488
error_setg(errp, "security_model property not set");
@@ -1516,11 +1516,10 @@ static int local_parse_opts(QemuOpts *opts, FsDriverEntry *fse, Error **errp)
15161516
fse->export_flags &= ~V9FS_FORBID_MULTIDEVS;
15171517
fse->export_flags &= ~V9FS_REMAP_INODES;
15181518
} else {
1519-
error_setg(&local_err, "invalid multidevs property '%s'",
1519+
error_setg(errp, "invalid multidevs property '%s'",
15201520
multidevs);
1521-
error_append_hint(&local_err, "Valid options are: multidevs="
1521+
error_append_hint(errp, "Valid options are: multidevs="
15221522
"[remap|forbid|warn]\n");
1523-
error_propagate(errp, local_err);
15241523
return -1;
15251524
}
15261525
}
@@ -1530,9 +1529,8 @@ static int local_parse_opts(QemuOpts *opts, FsDriverEntry *fse, Error **errp)
15301529
return -1;
15311530
}
15321531

1533-
if (fsdev_throttle_parse_opts(opts, &fse->fst, &local_err)) {
1534-
error_propagate_prepend(errp, local_err,
1535-
"invalid throttle configuration: ");
1532+
if (fsdev_throttle_parse_opts(opts, &fse->fst, errp)) {
1533+
error_prepend(errp, "invalid throttle configuration: ");
15361534
return -1;
15371535
}
15381536

hw/9pfs/9p.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4011,6 +4011,7 @@ void pdu_submit(V9fsPDU *pdu, P9MsgHeader *hdr)
40114011
int v9fs_device_realize_common(V9fsState *s, const V9fsTransport *t,
40124012
Error **errp)
40134013
{
4014+
ERRP_GUARD();
40144015
int i, len;
40154016
struct stat stat;
40164017
FsDriverEntry *fse;

0 commit comments

Comments
 (0)