Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

GuoHan Zhao and committed by
Juergen Gross
7f8862d2 f45ab277

+17 -3
+17 -3
drivers/xen/manage.c
··· 343 343 return err; 344 344 } 345 345 346 - 347 346 #ifdef CONFIG_MAGIC_SYSRQ 348 347 err = register_xenbus_watch(&sysrq_watch); 349 348 if (err) { 350 349 pr_err("Failed to set sysrq watcher\n"); 351 - return err; 350 + goto err_unregister_shutdown; 352 351 } 353 352 #endif 354 353 ··· 360 361 if (err) { 361 362 pr_err("%s: Error %d writing %s\n", __func__, 362 363 err, node); 363 - return err; 364 + goto err_remove_features; 364 365 } 365 366 } 366 367 367 368 return 0; 369 + 370 + err_remove_features: 371 + while (--idx >= 0) { 372 + if (!shutdown_handlers[idx].flag) 373 + continue; 374 + snprintf(node, FEATURE_PATH_SIZE, "feature-%s", 375 + shutdown_handlers[idx].command); 376 + xenbus_rm(XBT_NIL, "control", node); 377 + } 378 + #ifdef CONFIG_MAGIC_SYSRQ 379 + unregister_xenbus_watch(&sysrq_watch); 380 + err_unregister_shutdown: 381 + #endif 382 + unregister_xenbus_watch(&shutdown_watch); 383 + return err; 368 384 } 369 385 370 386 static int shutdown_event(struct notifier_block *notifier,