Skip to content

Commit 7f8862d

Browse files
GuoHan Zhaojgross1
authored andcommitted
xen/manage: unwind partial shutdown watcher setup on error
setup_shutdown_watcher() registers shutdown_watch first, then the sysrq watch, and finally publishes the supported feature-* nodes in xenstore. If sysrq watch registration fails, or xenbus_printf() fails after one or more feature nodes were created, the function returns immediately without undoing the earlier setup. This leaves the system in a partially initialized state, with registered watches and/or stale xenstore entries despite the function reporting failure. Unwind the partial setup before returning an error by unregistering any watches that were already registered and removing feature nodes that were already published. Signed-off-by: GuoHan Zhao <zhaoguohan@kylinos.cn> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org> Signed-off-by: Juergen Gross <jgross@suse.com> Message-ID: <20260407022443.12971-1-zhaoguohan@kylinos.cn>
1 parent f45ab27 commit 7f8862d

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

drivers/xen/manage.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,11 @@ static int setup_shutdown_watcher(void)
343343
return err;
344344
}
345345

346-
347346
#ifdef CONFIG_MAGIC_SYSRQ
348347
err = register_xenbus_watch(&sysrq_watch);
349348
if (err) {
350349
pr_err("Failed to set sysrq watcher\n");
351-
return err;
350+
goto err_unregister_shutdown;
352351
}
353352
#endif
354353

@@ -361,11 +360,26 @@ static int setup_shutdown_watcher(void)
361360
if (err) {
362361
pr_err("%s: Error %d writing %s\n", __func__,
363362
err, node);
364-
return err;
363+
goto err_remove_features;
365364
}
366365
}
367366

368367
return 0;
368+
369+
err_remove_features:
370+
while (--idx >= 0) {
371+
if (!shutdown_handlers[idx].flag)
372+
continue;
373+
snprintf(node, FEATURE_PATH_SIZE, "feature-%s",
374+
shutdown_handlers[idx].command);
375+
xenbus_rm(XBT_NIL, "control", node);
376+
}
377+
#ifdef CONFIG_MAGIC_SYSRQ
378+
unregister_xenbus_watch(&sysrq_watch);
379+
err_unregister_shutdown:
380+
#endif
381+
unregister_xenbus_watch(&shutdown_watch);
382+
return err;
369383
}
370384

371385
static int shutdown_event(struct notifier_block *notifier,

0 commit comments

Comments
 (0)