Skip to content

Commit 7a0b74d

Browse files
roygerdwmw2
authored andcommitted
xen: do not use '%ms' scanf specifier
The 'm' parameter used to request auto-allocation of the destination variable is not supported on FreeBSD, and as such leads to failures to parse. What's more, the current usage of '%ms' with xs_node_scanf() is pointless, as it just leads to a double allocation of the same string. Instead use xs_node_read() to read the whole xenstore node. Fixes: a783f8a ('xen: add a mechanism to automatically create XenDevice-s...') Fixes: 9b77374 ('hw/xen: update Xen console to XenDevice model') Signed-off-by: Roger Pau Monné <[email protected]> Signed-off-by: David Woodhouse <[email protected]> Reviewed-by: Anthony PERARD <[email protected]>
1 parent e6cdeee commit 7a0b74d

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

hw/block/xen-block.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ static void xen_block_connect(XenDevice *xendev, Error **errp)
239239
return;
240240
}
241241

242-
if (xen_device_frontend_scanf(xendev, "protocol", "%ms", &str) != 1) {
242+
str = xen_device_frontend_read(xendev, "protocol");
243+
if (!str) {
243244
/* x86 defaults to the 32-bit protocol even for 64-bit guests. */
244245
if (object_dynamic_cast(OBJECT(qdev_get_machine()), "x86-machine")) {
245246
protocol = BLKIF_PROTOCOL_X86_32;

hw/char/xen_console.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,8 @@ static void xen_console_device_create(XenBackendInstance *backend,
550550
goto fail;
551551
}
552552

553-
if (xs_node_scanf(xsh, XBT_NULL, fe, "type", errp, "%ms", &type) != 1) {
553+
type = xs_node_read(xsh, XBT_NULL, NULL, errp, "%s/%s", fe, "type");
554+
if (!type) {
554555
error_prepend(errp, "failed to read console device type: ");
555556
goto fail;
556557
}
@@ -568,7 +569,8 @@ static void xen_console_device_create(XenBackendInstance *backend,
568569

569570
snprintf(label, sizeof(label), "xencons%ld", number);
570571

571-
if (xs_node_scanf(xsh, XBT_NULL, fe, "output", NULL, "%ms", &output) == 1) {
572+
output = xs_node_read(xsh, XBT_NULL, NULL, NULL, "%s/%s", fe, "output");
573+
if (output) {
572574
/*
573575
* FIXME: sure we want to support implicit
574576
* muxed monitors here?

hw/xen/xen-bus.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ static void xen_bus_backend_create(XenBus *xenbus, const char *type,
156156
!strcmp(key[i], "hotplug-status"))
157157
continue;
158158

159-
if (xs_node_scanf(xenbus->xsh, tid, path, key[i], NULL, "%ms",
160-
&val) == 1) {
159+
val = xs_node_read(xenbus->xsh, tid, NULL, NULL, "%s/%s", path, key[i]);
160+
if (val) {
161161
qdict_put_str(opts, key[i], val);
162162
free(val);
163163
}
@@ -650,6 +650,16 @@ int xen_device_frontend_scanf(XenDevice *xendev, const char *key,
650650
return rc;
651651
}
652652

653+
char *xen_device_frontend_read(XenDevice *xendev, const char *key)
654+
{
655+
XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev)));
656+
657+
g_assert(xenbus->xsh);
658+
659+
return xs_node_read(xenbus->xsh, XBT_NULL, NULL, NULL, "%s/%s",
660+
xendev->frontend_path, key);
661+
}
662+
653663
static void xen_device_frontend_set_state(XenDevice *xendev,
654664
enum xenbus_state state,
655665
bool publish)

include/hw/xen/xen-bus.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ void xen_device_frontend_printf(XenDevice *xendev, const char *key,
9191
int xen_device_frontend_scanf(XenDevice *xendev, const char *key,
9292
const char *fmt, ...)
9393
G_GNUC_SCANF(3, 4);
94+
char *xen_device_frontend_read(XenDevice *xendev, const char *key);
9495

9596
void xen_device_set_max_grant_refs(XenDevice *xendev, unsigned int nr_refs,
9697
Error **errp);

0 commit comments

Comments
 (0)