* [PATCH] ui/gtk: fix UI info precondition
@ 2023-09-15 11:36 marcandre.lureau
2023-09-15 12:45 ` Michael Tokarev
0 siblings, 1 reply; 3+ messages in thread
From: marcandre.lureau @ 2023-09-15 11:36 UTC (permalink / raw)
To: qemu-devel; +Cc: berrange, kraxel, Marc-André Lureau
From: Marc-André Lureau <marcandre.lureau@redhat.com>
dpy_get_ui_info() shouldn't be called if the underlying GPU doesn't
support it.
Before the assert() was added and the regression introduced, GTK code
used to get "zero" UI info, for ex with a simple VGA device. The assert
was added to prevent from calling when there are no console too. The
other display backend that calls dpy_get_ui_info() correctly checks that
pre-condition.
Calling dpy_set_ui_info() is "safe" in this case, it will simply return
an error that can be generally ignored.
Fixes: commit a92e7bb4c ("ui: add precondition for dpy_get_ui_info()")
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
ui/gtk.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/ui/gtk.c b/ui/gtk.c
index e09f97a86b..7b542da0c0 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -726,6 +726,10 @@ static void gd_set_ui_refresh_rate(VirtualConsole *vc, int refresh_rate)
{
QemuUIInfo info;
+ if (!dpy_ui_info_supported(vc->gfx.dcl.con)) {
+ return;
+ }
+
info = *dpy_get_ui_info(vc->gfx.dcl.con);
info.refresh_rate = refresh_rate;
dpy_set_ui_info(vc->gfx.dcl.con, &info, true);
@@ -735,6 +739,10 @@ static void gd_set_ui_size(VirtualConsole *vc, gint width, gint height)
{
QemuUIInfo info;
+ if (!dpy_ui_info_supported(vc->gfx.dcl.con)) {
+ return;
+ }
+
info = *dpy_get_ui_info(vc->gfx.dcl.con);
info.width = width;
info.height = height;
--
2.41.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ui/gtk: fix UI info precondition
2023-09-15 11:36 [PATCH] ui/gtk: fix UI info precondition marcandre.lureau
@ 2023-09-15 12:45 ` Michael Tokarev
2023-09-18 11:06 ` Marc-André Lureau
0 siblings, 1 reply; 3+ messages in thread
From: Michael Tokarev @ 2023-09-15 12:45 UTC (permalink / raw)
To: marcandre.lureau, qemu-devel; +Cc: berrange, kraxel
15.09.2023 14:36, marcandre.lureau@redhat.com:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> dpy_get_ui_info() shouldn't be called if the underlying GPU doesn't
> support it.
>
> Before the assert() was added and the regression introduced, GTK code
> used to get "zero" UI info, for ex with a simple VGA device. The assert
> was added to prevent from calling when there are no console too. The
> other display backend that calls dpy_get_ui_info() correctly checks that
> pre-condition.
>
> Calling dpy_set_ui_info() is "safe" in this case, it will simply return
> an error that can be generally ignored.
>
> Fixes: commit a92e7bb4c ("ui: add precondition for dpy_get_ui_info()")
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> ui/gtk.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/ui/gtk.c b/ui/gtk.c
> index e09f97a86b..7b542da0c0 100644
> --- a/ui/gtk.c
> +++ b/ui/gtk.c
> @@ -726,6 +726,10 @@ static void gd_set_ui_refresh_rate(VirtualConsole *vc, int refresh_rate)
> {
> QemuUIInfo info;
>
> + if (!dpy_ui_info_supported(vc->gfx.dcl.con)) {
> + return;
> + }
> +
> info = *dpy_get_ui_info(vc->gfx.dcl.con);
Current dpy_ui_info_supported():
bool dpy_ui_info_supported(QemuConsole *con)
{
if (con == NULL) {
con = active_console;
}
if (con == NULL) {
return false;
}
return con->hw_ops->ui_info != NULL;
}
This whole thing smells a bit wrong. I'm not saying it *is* wrong, but
the feeling is here.
Where dpy_ui_info_supported() is called with a NULL con, so that an "active"
console needs to be used instead?
Maybe we should instead use something like
if (!vc->gfx.dcl.con)
here in gd_set_ui_refresh_rate() ?
At the very least, the code is a bit, well, confusing.
/mjt
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ui/gtk: fix UI info precondition
2023-09-15 12:45 ` Michael Tokarev
@ 2023-09-18 11:06 ` Marc-André Lureau
0 siblings, 0 replies; 3+ messages in thread
From: Marc-André Lureau @ 2023-09-18 11:06 UTC (permalink / raw)
To: Michael Tokarev; +Cc: qemu-devel, berrange, kraxel
Hi
On Fri, Sep 15, 2023 at 4:46 PM Michael Tokarev <mjt@tls.msk.ru> wrote:
>
> 15.09.2023 14:36, marcandre.lureau@redhat.com:
> > From: Marc-André Lureau <marcandre.lureau@redhat.com>
> >
> > dpy_get_ui_info() shouldn't be called if the underlying GPU doesn't
> > support it.
> >
> > Before the assert() was added and the regression introduced, GTK code
> > used to get "zero" UI info, for ex with a simple VGA device. The assert
> > was added to prevent from calling when there are no console too. The
> > other display backend that calls dpy_get_ui_info() correctly checks that
> > pre-condition.
> >
> > Calling dpy_set_ui_info() is "safe" in this case, it will simply return
> > an error that can be generally ignored.
> >
> > Fixes: commit a92e7bb4c ("ui: add precondition for dpy_get_ui_info()")
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> > ui/gtk.c | 8 ++++++++
> > 1 file changed, 8 insertions(+)
> >
> > diff --git a/ui/gtk.c b/ui/gtk.c
> > index e09f97a86b..7b542da0c0 100644
> > --- a/ui/gtk.c
> > +++ b/ui/gtk.c
> > @@ -726,6 +726,10 @@ static void gd_set_ui_refresh_rate(VirtualConsole *vc, int refresh_rate)
> > {
> > QemuUIInfo info;
> >
> > + if (!dpy_ui_info_supported(vc->gfx.dcl.con)) {
> > + return;
> > + }
> > +
> > info = *dpy_get_ui_info(vc->gfx.dcl.con);
>
> Current dpy_ui_info_supported():
>
> bool dpy_ui_info_supported(QemuConsole *con)
> {
> if (con == NULL) {
> con = active_console;
> }
> if (con == NULL) {
> return false;
> }
>
> return con->hw_ops->ui_info != NULL;
> }
>
> This whole thing smells a bit wrong. I'm not saying it *is* wrong, but
> the feeling is here.
>
> Where dpy_ui_info_supported() is called with a NULL con, so that an "active"
> console needs to be used instead?
>
> Maybe we should instead use something like
>
> if (!vc->gfx.dcl.con)
>
> here in gd_set_ui_refresh_rate() ?
>
> At the very least, the code is a bit, well, confusing.
I agree it's a bit confusing to have dpy_*() functions accept NULL
arguments to mean "active_console". I don't really have a good idea
what to do else. Just having "if (!vc->gfx.dcl.con)" is not quite
enough though, as we shouldn't get_ui_info() if it's not supported
(there are no errors returned then, just "invalid/zero" values).
--
Marc-André Lureau
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-09-18 11:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-15 11:36 [PATCH] ui/gtk: fix UI info precondition marcandre.lureau
2023-09-15 12:45 ` Michael Tokarev
2023-09-18 11:06 ` Marc-André Lureau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).