qdev: Make DeviceState.id independent of QemuOpts

DeviceState.id is a pointer to a string that is stored in the QemuOpts
object DeviceState.opts and freed together with it. We want to create
devices without going through QemuOpts in the future, so make this a
separately allocated string.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20211008133442.141332-9-kwolf@redhat.com>
Reviewed-by: Damien Hedde <damien.hedde@greensocs.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Kevin Wolf 2021-10-08 15:34:35 +02:00
parent c34efecedd
commit 163f384752
7 changed files with 9 additions and 7 deletions

View file

@ -592,7 +592,8 @@ static BusState *qbus_find(const char *path, Error **errp)
return bus;
}
void qdev_set_id(DeviceState *dev, const char *id)
/* Takes ownership of @id, will be freed when deleting the device */
void qdev_set_id(DeviceState *dev, char *id)
{
if (id) {
dev->id = id;
@ -690,7 +691,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
}
}
qdev_set_id(dev, qemu_opts_id(opts));
qdev_set_id(dev, g_strdup(qemu_opts_id(opts)));
/* set properties */
if (qemu_opt_foreach(opts, set_property, dev, errp)) {