Re: [RFC PATCH] char-fe: implement qemu_chr_fe_backend_name
Philippe Mathieu-Daudé <[email protected]>
| Newsgroups | org.nongnu.qemu-arm,org.nongnu.qemu-devel |
|---|---|
| Message-ID | <[email protected]> |
On 10/8/26 17:35, Alex Bennée wrote: > 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. > > Signed-off-by: Alex Bennée <[email protected]> > Suggested-by: Peter Maydell <[email protected]> > --- > include/chardev/char-fe.h | 13 ++++++++++++- > backends/cryptodev-vhost-user.c | 8 +------- > backends/rng-egd.c | 8 +------- > backends/vhost-user.c | 8 +------- > hw/char/imx_serial.c | 4 ++-- > 5 files changed, 17 insertions(+), 24 deletions(-) > > diff --git a/include/chardev/char-fe.h b/include/chardev/char-fe.h > index 5f8a6df17dc..13218d04c8d 100644 > --- a/include/chardev/char-fe.h > +++ b/include/chardev/char-fe.h > @@ -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; > +} This looks like a safe setter for the "chardev" ObjectProperty. Maybe we could go one step further and unify adding a object_class_property_add_chardev() helper?