From nobody Sun Apr 12 22:39:44 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 556461E3DDE for ; Tue, 7 Apr 2026 02:24:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775528697; cv=none; b=l33L/zjbbFsC/6Yvcxj36Jei6dCz6wPPjrA/cO/LxHDyT78ExEoDUB4UhH57ZDPKrP44UJyw0Ex8xJzALNEa5L6dCYqqFquSNg4j1PyXHFoqsx6KGdByNIAwiuhlLL/eHJbU7e2hNvIhvz34TouAAQo3jsStPsqo1tq+Ob28akI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775528697; c=relaxed/simple; bh=R+GgqeilthAK/zwYR5Tb2BgGPnMS7O4tUvwgk47GRaw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=dv9NR4aEmA4IN8h/M7GezJkpS6vW+ymzSdCA+7Vmx2es1Dbx27fTvKzp+CfqHDAW/Z0IeOprl7JZ2v0Tc3NdiUeZAo1P+1yPUPuyzacVfvnIQ+B86sXV9XzpU3DDL+cUzEVj0BsF2W97dt4Xa7hLtgPBsBugTp4jolkZUUP+gNU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: f224c9a4322811f1aa26b74ffac11d73-20260407 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.12,REQID:7e94b4d7-7953-4c7f-a6e2-6f9af9de78fd,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:e7bac3a,CLOUDID:7435d5df1d566edbeea2e54162a75b2b,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:102|123|850|898,TC:nil,Content:0|15|50,E DM:-3,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA :0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: f224c9a4322811f1aa26b74ffac11d73-20260407 X-User: zhaoguohan@kylinos.cn Received: from localhost.localdomain [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 730094213; Tue, 07 Apr 2026 10:24:46 +0800 From: zhaoguohan@kylinos.cn To: jgross@suse.com, sstabellini@kernel.org Cc: oleksandr_tyshchenko@epam.com, xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, GuoHan Zhao Subject: [PATCH] xen/manage: unwind partial shutdown watcher setup on error Date: Tue, 7 Apr 2026 10:24:43 +0800 Message-ID: <20260407022443.12971-1-zhaoguohan@kylinos.cn> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: GuoHan Zhao 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 Reviewed-by: Stefano Stabellini --- drivers/xen/manage.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c index e20c40a62e64..18bf09e0192a 100644 --- a/drivers/xen/manage.c +++ b/drivers/xen/manage.c @@ -343,12 +343,11 @@ static int setup_shutdown_watcher(void) return err; } =20 - #ifdef CONFIG_MAGIC_SYSRQ err =3D register_xenbus_watch(&sysrq_watch); if (err) { pr_err("Failed to set sysrq watcher\n"); - return err; + goto err_unregister_shutdown; } #endif =20 @@ -361,11 +360,26 @@ static int setup_shutdown_watcher(void) if (err) { pr_err("%s: Error %d writing %s\n", __func__, err, node); - return err; + goto err_remove_features; } } =20 return 0; + +err_remove_features: + while (--idx >=3D 0) { + if (!shutdown_handlers[idx].flag) + continue; + snprintf(node, FEATURE_PATH_SIZE, "feature-%s", + shutdown_handlers[idx].command); + xenbus_rm(XBT_NIL, "control", node); + } +#ifdef CONFIG_MAGIC_SYSRQ + unregister_xenbus_watch(&sysrq_watch); +#endif +err_unregister_shutdown: + unregister_xenbus_watch(&shutdown_watch); + return err; } =20 static int shutdown_event(struct notifier_block *notifier, --=20 2.43.0