mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 08:13:54 -06:00
xen: 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). No such cases are being fixed here. This commit is generated by command sed -n '/^X86 Xen CPUs$/,/^$/{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 <kwolf@redhat.com> Reported-by: Greg Kurz <groug@kaod.org> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> [Commit message tweaked] Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20200707165037.1026246-9-armbru@redhat.com> [ERRP_AUTO_PROPAGATE() renamed to ERRP_GUARD(), and auto-propagated-errp.cocci to errp-guard.cocci. Commit message tweaked again.]
This commit is contained in:
parent
795d946d07
commit
1de7096d83
8 changed files with 128 additions and 166 deletions
|
@ -53,9 +53,9 @@ static char *xen_device_get_frontend_path(XenDevice *xendev)
|
|||
|
||||
static void xen_device_unplug(XenDevice *xendev, Error **errp)
|
||||
{
|
||||
ERRP_GUARD();
|
||||
XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev)));
|
||||
const char *type = object_get_typename(OBJECT(xendev));
|
||||
Error *local_err = NULL;
|
||||
xs_transaction_t tid;
|
||||
|
||||
trace_xen_device_unplug(type, xendev->name);
|
||||
|
@ -69,14 +69,14 @@ again:
|
|||
}
|
||||
|
||||
xs_node_printf(xenbus->xsh, tid, xendev->backend_path, "online",
|
||||
&local_err, "%u", 0);
|
||||
if (local_err) {
|
||||
errp, "%u", 0);
|
||||
if (*errp) {
|
||||
goto abort;
|
||||
}
|
||||
|
||||
xs_node_printf(xenbus->xsh, tid, xendev->backend_path, "state",
|
||||
&local_err, "%u", XenbusStateClosing);
|
||||
if (local_err) {
|
||||
errp, "%u", XenbusStateClosing);
|
||||
if (*errp) {
|
||||
goto abort;
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,6 @@ abort:
|
|||
* from ending the transaction.
|
||||
*/
|
||||
xs_transaction_end(xenbus->xsh, tid, true);
|
||||
error_propagate(errp, local_err);
|
||||
}
|
||||
|
||||
static void xen_bus_print_dev(Monitor *mon, DeviceState *dev, int indent)
|
||||
|
@ -205,15 +204,13 @@ static XenWatch *watch_list_add(XenWatchList *watch_list, const char *node,
|
|||
const char *key, XenWatchHandler handler,
|
||||
void *opaque, Error **errp)
|
||||
{
|
||||
ERRP_GUARD();
|
||||
XenWatch *watch = new_watch(node, key, handler, opaque);
|
||||
Error *local_err = NULL;
|
||||
|
||||
notifier_list_add(&watch_list->notifiers, &watch->notifier);
|
||||
|
||||
xs_node_watch(watch_list->xsh, node, key, watch->token, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
|
||||
xs_node_watch(watch_list->xsh, node, key, watch->token, errp);
|
||||
if (*errp) {
|
||||
notifier_remove(&watch->notifier);
|
||||
free_watch(watch);
|
||||
|
||||
|
@ -255,11 +252,11 @@ static void xen_bus_backend_create(XenBus *xenbus, const char *type,
|
|||
const char *name, char *path,
|
||||
Error **errp)
|
||||
{
|
||||
ERRP_GUARD();
|
||||
xs_transaction_t tid;
|
||||
char **key;
|
||||
QDict *opts;
|
||||
unsigned int i, n;
|
||||
Error *local_err = NULL;
|
||||
|
||||
trace_xen_bus_backend_create(type, path);
|
||||
|
||||
|
@ -314,13 +311,11 @@ again:
|
|||
return;
|
||||
}
|
||||
|
||||
xen_backend_device_create(xenbus, type, name, opts, &local_err);
|
||||
xen_backend_device_create(xenbus, type, name, opts, errp);
|
||||
qobject_unref(opts);
|
||||
|
||||
if (local_err) {
|
||||
error_propagate_prepend(errp, local_err,
|
||||
"failed to create '%s' device '%s': ",
|
||||
type, name);
|
||||
if (*errp) {
|
||||
error_prepend(errp, "failed to create '%s' device '%s': ", type, name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -692,9 +687,9 @@ static void xen_device_remove_watch(XenDevice *xendev, XenWatch *watch,
|
|||
|
||||
static void xen_device_backend_create(XenDevice *xendev, Error **errp)
|
||||
{
|
||||
ERRP_GUARD();
|
||||
XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev)));
|
||||
struct xs_permissions perms[2];
|
||||
Error *local_err = NULL;
|
||||
|
||||
xendev->backend_path = xen_device_get_backend_path(xendev);
|
||||
|
||||
|
@ -706,30 +701,27 @@ static void xen_device_backend_create(XenDevice *xendev, Error **errp)
|
|||
g_assert(xenbus->xsh);
|
||||
|
||||
xs_node_create(xenbus->xsh, XBT_NULL, xendev->backend_path, perms,
|
||||
ARRAY_SIZE(perms), &local_err);
|
||||
if (local_err) {
|
||||
error_propagate_prepend(errp, local_err,
|
||||
"failed to create backend: ");
|
||||
ARRAY_SIZE(perms), errp);
|
||||
if (*errp) {
|
||||
error_prepend(errp, "failed to create backend: ");
|
||||
return;
|
||||
}
|
||||
|
||||
xendev->backend_state_watch =
|
||||
xen_device_add_watch(xendev, xendev->backend_path,
|
||||
"state", xen_device_backend_changed,
|
||||
&local_err);
|
||||
if (local_err) {
|
||||
error_propagate_prepend(errp, local_err,
|
||||
"failed to watch backend state: ");
|
||||
errp);
|
||||
if (*errp) {
|
||||
error_prepend(errp, "failed to watch backend state: ");
|
||||
return;
|
||||
}
|
||||
|
||||
xendev->backend_online_watch =
|
||||
xen_device_add_watch(xendev, xendev->backend_path,
|
||||
"online", xen_device_backend_changed,
|
||||
&local_err);
|
||||
if (local_err) {
|
||||
error_propagate_prepend(errp, local_err,
|
||||
"failed to watch backend online: ");
|
||||
errp);
|
||||
if (*errp) {
|
||||
error_prepend(errp, "failed to watch backend online: ");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -866,9 +858,9 @@ static bool xen_device_frontend_exists(XenDevice *xendev)
|
|||
|
||||
static void xen_device_frontend_create(XenDevice *xendev, Error **errp)
|
||||
{
|
||||
ERRP_GUARD();
|
||||
XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev)));
|
||||
struct xs_permissions perms[2];
|
||||
Error *local_err = NULL;
|
||||
|
||||
xendev->frontend_path = xen_device_get_frontend_path(xendev);
|
||||
|
||||
|
@ -885,20 +877,18 @@ static void xen_device_frontend_create(XenDevice *xendev, Error **errp)
|
|||
g_assert(xenbus->xsh);
|
||||
|
||||
xs_node_create(xenbus->xsh, XBT_NULL, xendev->frontend_path, perms,
|
||||
ARRAY_SIZE(perms), &local_err);
|
||||
if (local_err) {
|
||||
error_propagate_prepend(errp, local_err,
|
||||
"failed to create frontend: ");
|
||||
ARRAY_SIZE(perms), errp);
|
||||
if (*errp) {
|
||||
error_prepend(errp, "failed to create frontend: ");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
xendev->frontend_state_watch =
|
||||
xen_device_add_watch(xendev, xendev->frontend_path, "state",
|
||||
xen_device_frontend_changed, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate_prepend(errp, local_err,
|
||||
"failed to watch frontend state: ");
|
||||
xen_device_frontend_changed, errp);
|
||||
if (*errp) {
|
||||
error_prepend(errp, "failed to watch frontend state: ");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1247,11 +1237,11 @@ static void xen_device_exit(Notifier *n, void *data)
|
|||
|
||||
static void xen_device_realize(DeviceState *dev, Error **errp)
|
||||
{
|
||||
ERRP_GUARD();
|
||||
XenDevice *xendev = XEN_DEVICE(dev);
|
||||
XenDeviceClass *xendev_class = XEN_DEVICE_GET_CLASS(xendev);
|
||||
XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev)));
|
||||
const char *type = object_get_typename(OBJECT(xendev));
|
||||
Error *local_err = NULL;
|
||||
|
||||
if (xendev->frontend_id == DOMID_INVALID) {
|
||||
xendev->frontend_id = xen_domid;
|
||||
|
@ -1267,10 +1257,9 @@ static void xen_device_realize(DeviceState *dev, Error **errp)
|
|||
goto unrealize;
|
||||
}
|
||||
|
||||
xendev->name = xendev_class->get_name(xendev, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate_prepend(errp, local_err,
|
||||
"failed to get device name: ");
|
||||
xendev->name = xendev_class->get_name(xendev, errp);
|
||||
if (*errp) {
|
||||
error_prepend(errp, "failed to get device name: ");
|
||||
goto unrealize;
|
||||
}
|
||||
|
||||
|
@ -1293,22 +1282,19 @@ static void xen_device_realize(DeviceState *dev, Error **errp)
|
|||
xendev->feature_grant_copy =
|
||||
(xengnttab_grant_copy(xendev->xgth, 0, NULL) == 0);
|
||||
|
||||
xen_device_backend_create(xendev, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
xen_device_backend_create(xendev, errp);
|
||||
if (*errp) {
|
||||
goto unrealize;
|
||||
}
|
||||
|
||||
xen_device_frontend_create(xendev, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
xen_device_frontend_create(xendev, errp);
|
||||
if (*errp) {
|
||||
goto unrealize;
|
||||
}
|
||||
|
||||
if (xendev_class->realize) {
|
||||
xendev_class->realize(xendev, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
xendev_class->realize(xendev, errp);
|
||||
if (*errp) {
|
||||
goto unrealize;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue