char-fe: implement qemu_chr_fe_backend_name
A number of chardev users where calling qemu_chr_fe_get_driver() which is discouraged as it blocks backend hotswap. As the pattern is common and need for the string is transitory add a helper and keep qemu_chr_fe_get_driver() for those that really need the funkiness of poking around the backend setup. Suggested-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260824-fixes-for-11-2-v2-4-352c6b890402@linaro.org> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
This commit is contained in:
1 parent
172cc8e4c5
commit
6b375e13b2
5 files changed
+17
-24
No files matched your search
@@ -373,13 +373,7 @@ cryptodev_vhost_user_get_chardev(Object *obj, Error **errp)
|
||||
{
|
||||
CryptoDevBackendVhostUser *s =
|
||||
CRYPTODEV_BACKEND_VHOST_USER(obj);
|
||||
Chardev *chr = qemu_chr_fe_get_driver(&s->chr);
|
||||
|
||||
if (chr && chr->label) {
|
||||
return g_strdup(chr->label);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return qemu_chr_fe_backend_name(&s->chr);
|
||||
}
|
||||
|
||||
static void cryptodev_vhost_user_finalize(Object *obj)
|
||||
|
||||
+1
-7
@@ -126,13 +126,7 @@ static void rng_egd_set_chardev(Object *obj, const char *value, Error **errp)
|
||||
static char *rng_egd_get_chardev(Object *obj, Error **errp)
|
||||
{
|
||||
RngEgd *s = RNG_EGD(obj);
|
||||
Chardev *chr = qemu_chr_fe_get_driver(&s->chr);
|
||||
|
||||
if (chr && chr->label) {
|
||||
return g_strdup(chr->label);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return qemu_chr_fe_backend_name(&s->chr);
|
||||
}
|
||||
|
||||
static void rng_egd_finalize(Object *obj)
|
||||
|
||||
@@ -152,13 +152,7 @@ static void set_chardev(Object *obj, const char *value, Error **errp)
|
||||
static char *get_chardev(Object *obj, Error **errp)
|
||||
{
|
||||
VhostUserBackend *b = VHOST_USER_BACKEND(obj);
|
||||
Chardev *chr = qemu_chr_fe_get_driver(&b->chr);
|
||||
|
||||
if (chr && chr->label) {
|
||||
return g_strdup(chr->label);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return qemu_chr_fe_backend_name(&b->chr);
|
||||
}
|
||||
|
||||
static void vhost_user_backend_class_init(ObjectClass *oc, const void *data)
|
||||
|
||||
@@ -278,10 +278,10 @@ static void imx_serial_write(void *opaque, hwaddr offset,
|
||||
uint64_t value, unsigned size)
|
||||
{
|
||||
IMXSerialState *s = (IMXSerialState *)opaque;
|
||||
Chardev *chr = qemu_chr_fe_get_driver(&s->chr);
|
||||
g_autofree char *label = qemu_chr_fe_backend_name(&s->chr);
|
||||
unsigned char ch;
|
||||
|
||||
trace_imx_serial_write(chr ? chr->label : "NODEV", offset, value);
|
||||
trace_imx_serial_write(label ? label : "NODEV", offset, value);
|
||||
|
||||
switch (offset >> 2) {
|
||||
case 0x10: /* UTXD */
|
||||
|
||||
@@ -52,7 +52,8 @@ void qemu_chr_fe_deinit(CharFrontend *c, bool del);
|
||||
* associated Chardev.
|
||||
* Note: avoid this function as the driver should never be accessed directly,
|
||||
* especially by the frontends that support chardevice hotswap.
|
||||
* Consider qemu_chr_fe_backend_connected() to check for driver existence
|
||||
* Consider qemu_chr_fe_backend_connected() to check for driver
|
||||
* existence or qemu_chr_fe_backend_name() if you need the name.
|
||||
*/
|
||||
Chardev *qemu_chr_fe_get_driver(CharFrontend *c);
|
||||
|
||||
@@ -70,6 +71,16 @@ bool qemu_chr_fe_backend_connected(CharFrontend *c);
|
||||
*/
|
||||
bool qemu_chr_fe_backend_open(CharFrontend *c);
|
||||
|
||||
/**
|
||||
* qemu_chr_fe_backend_name:
|
||||
*
|
||||
* Returns: caller freeable string or NULL
|
||||
*/
|
||||
static inline char *qemu_chr_fe_backend_name(CharFrontend *c)
|
||||
{
|
||||
return (c->chr && c->chr->label) ? g_strdup(c->chr->label) : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* qemu_chr_fe_set_handlers_full:
|
||||
* @c: a CharFrontend
|
||||
|
||||
Reference in new issue
Block a user