Skip to content

Commit 8b44a3e

Browse files
committed
hw/xen: Fix errp handling in xen_console
When attempting to read the 'output' node, interpret any error *other* than ENOENT as a fatal error. For ENOENT, fall back to serial_hd() to find a character device, or create a null device. Do not attempt to prepend to errp when serial_hd() fails; the error isn't relevant (and prior to this change, wasn't set anyway). Signed-off-by: David Woodhouse <[email protected]> Reviewed-by: Anthony PERARD <[email protected]>
1 parent cd414c3 commit 8b44a3e

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

hw/char/xen_console.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ static void xen_console_device_create(XenBackendInstance *backend,
569569

570570
snprintf(label, sizeof(label), "xencons%ld", number);
571571

572-
output = xs_node_read(xsh, XBT_NULL, NULL, NULL, "%s/%s", fe, "output");
572+
output = xs_node_read(xsh, XBT_NULL, NULL, errp, "%s/%s", fe, "output");
573573
if (output) {
574574
/*
575575
* FIXME: sure we want to support implicit
@@ -581,19 +581,27 @@ static void xen_console_device_create(XenBackendInstance *backend,
581581
output);
582582
goto fail;
583583
}
584-
} else if (number) {
585-
cd = serial_hd(number);
586-
if (!cd) {
587-
error_prepend(errp, "console: No serial device #%ld found: ",
588-
number);
589-
goto fail;
590-
}
584+
} else if (errno != ENOENT) {
585+
error_prepend(errp, "console: No valid chardev found: ");
586+
goto fail;
591587
} else {
592-
/* No 'output' node on primary console: use null. */
593-
cd = qemu_chr_new(label, "null", NULL);
594-
if (!cd) {
595-
error_setg(errp, "console: failed to create null device");
596-
goto fail;
588+
error_free(*errp);
589+
*errp = NULL;
590+
591+
if (number) {
592+
cd = serial_hd(number);
593+
if (!cd) {
594+
error_setg(errp, "console: No serial device #%ld found",
595+
number);
596+
goto fail;
597+
}
598+
} else {
599+
/* No 'output' node on primary console: use null. */
600+
cd = qemu_chr_new(label, "null", NULL);
601+
if (!cd) {
602+
error_setg(errp, "console: failed to create null device");
603+
goto fail;
604+
}
597605
}
598606
}
599607

0 commit comments

Comments
 (0)