aboutsummaryrefslogtreecommitdiff
path: root/qemu-char.c
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2016-10-22 12:52:59 +0300
committerPaolo Bonzini <pbonzini@redhat.com>2016-10-24 15:27:21 +0200
commitfa394ed625731c18f904578903718bf16617fe92 (patch)
tree224ba9825ba286e3fcffc48394a3a4c1afbc9531 /qemu-char.c
parentc39860e6dc90f6ee2e82ee078f978c5d7f3df86a (diff)
char: make some qemu_chr_fe skip if no driver
In most cases, front ends do not care about the side effect of CharBackend, so we can simply skip the checks and call the qemu_chr_fe functions even without associated CharDriver. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20161022095318.17775-20-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'qemu-char.c')
-rw-r--r--qemu-char.c50
1 files changed, 42 insertions, 8 deletions
diff --git a/qemu-char.c b/qemu-char.c
index e5e80381d7..3bfde82b04 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -273,6 +273,10 @@ int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len)
CharDriverState *s = be->chr;
int ret;
+ if (!s) {
+ return 0;
+ }
+
if (s->replay && replay_mode == REPLAY_MODE_PLAY) {
int offset;
replay_char_write_event_load(&ret, &offset);
@@ -325,6 +329,10 @@ int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len)
{
CharDriverState *s = be->chr;
+ if (!s) {
+ return 0;
+ }
+
return qemu_chr_write_all(s, buf, len);
}
@@ -334,10 +342,10 @@ int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len)
int offset = 0, counter = 10;
int res;
- if (!s->chr_sync_read) {
+ if (!s || !s->chr_sync_read) {
return 0;
}
-
+
if (s->replay && replay_mode == REPLAY_MODE_PLAY) {
return replay_char_read_all_load(buf);
}
@@ -378,7 +386,8 @@ int qemu_chr_fe_ioctl(CharBackend *be, int cmd, void *arg)
{
CharDriverState *s = be->chr;
int res;
- if (!s->chr_ioctl || s->replay) {
+
+ if (!s || !s->chr_ioctl || s->replay) {
res = -ENOTSUP;
} else {
res = s->chr_ioctl(s, cmd, arg);
@@ -418,7 +427,7 @@ int qemu_chr_fe_get_msgfd(CharBackend *be)
CharDriverState *s = be->chr;
int fd;
int res = (qemu_chr_fe_get_msgfds(be, &fd, 1) == 1) ? fd : -1;
- if (s->replay) {
+ if (s && s->replay) {
fprintf(stderr,
"Replay: get msgfd is not supported for serial devices yet\n");
exit(1);
@@ -430,6 +439,10 @@ int qemu_chr_fe_get_msgfds(CharBackend *be, int *fds, int len)
{
CharDriverState *s = be->chr;
+ if (!s) {
+ return -1;
+ }
+
return s->get_msgfds ? s->get_msgfds(s, fds, len) : -1;
}
@@ -437,6 +450,10 @@ int qemu_chr_fe_set_msgfds(CharBackend *be, int *fds, int num)
{
CharDriverState *s = be->chr;
+ if (!s) {
+ return -1;
+ }
+
return s->set_msgfds ? s->set_msgfds(s, fds, num) : -1;
}
@@ -449,6 +466,10 @@ void qemu_chr_fe_accept_input(CharBackend *be)
{
CharDriverState *s = be->chr;
+ if (!s) {
+ return;
+ }
+
if (s->chr_accept_input)
s->chr_accept_input(s);
qemu_notify_event();
@@ -945,6 +966,10 @@ void qemu_chr_fe_set_handlers(CharBackend *b,
void qemu_chr_fe_take_focus(CharBackend *b)
{
+ if (!b->chr) {
+ return;
+ }
+
if (b->chr->is_mux) {
mux_set_focus(b->chr->opaque, b->tag);
}
@@ -3347,6 +3372,11 @@ static int qemu_chr_wait_connected(CharDriverState *chr, Error **errp)
int qemu_chr_fe_wait_connected(CharBackend *be, Error **errp)
{
+ if (!be->chr) {
+ error_setg(errp, "missing associated backend");
+ return -1;
+ }
+
return qemu_chr_wait_connected(be->chr, errp);
}
@@ -4151,7 +4181,7 @@ void qemu_chr_fe_set_echo(CharBackend *be, bool echo)
{
CharDriverState *chr = be->chr;
- if (chr->chr_set_echo) {
+ if (chr && chr->chr_set_echo) {
chr->chr_set_echo(chr, echo);
}
}
@@ -4160,6 +4190,10 @@ void qemu_chr_fe_set_open(CharBackend *be, int fe_open)
{
CharDriverState *chr = be->chr;
+ if (!chr) {
+ return;
+ }
+
if (chr->fe_open == fe_open) {
return;
}
@@ -4173,7 +4207,7 @@ void qemu_chr_fe_event(CharBackend *be, int event)
{
CharDriverState *chr = be->chr;
- if (chr->chr_fe_event) {
+ if (chr && chr->chr_fe_event) {
chr->chr_fe_event(chr, event);
}
}
@@ -4185,7 +4219,7 @@ guint qemu_chr_fe_add_watch(CharBackend *be, GIOCondition cond,
GSource *src;
guint tag;
- if (s->chr_add_watch == NULL) {
+ if (!s || s->chr_add_watch == NULL) {
return 0;
}
@@ -4205,7 +4239,7 @@ void qemu_chr_fe_disconnect(CharBackend *be)
{
CharDriverState *chr = be->chr;
- if (chr->chr_disconnect) {
+ if (chr && chr->chr_disconnect) {
chr->chr_disconnect(chr);
}
}