Commit db39fcf1 authored by Paolo Bonzini's avatar Paolo Bonzini Committed by Luiz Capitulino

qemu-char: introduce qemu_chr_alloc

The next patch will modify this function to initialize state that is
common to all backends.
Reviewed-by: default avatarFam Zheng <famz@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: default avatarLuiz Capitulino <lcapitulino@redhat.com>
parent 75175173
...@@ -574,7 +574,7 @@ CharDriverState *chr_baum_init(void) ...@@ -574,7 +574,7 @@ CharDriverState *chr_baum_init(void)
int tty; int tty;
baum = g_malloc0(sizeof(BaumDriverState)); baum = g_malloc0(sizeof(BaumDriverState));
baum->chr = chr = g_malloc0(sizeof(CharDriverState)); baum->chr = chr = qemu_chr_alloc();
chr->opaque = baum; chr->opaque = baum;
chr->chr_write = baum_write; chr->chr_write = baum_write;
......
...@@ -67,7 +67,7 @@ CharDriverState *qemu_chr_open_msmouse(void) ...@@ -67,7 +67,7 @@ CharDriverState *qemu_chr_open_msmouse(void)
{ {
CharDriverState *chr; CharDriverState *chr;
chr = g_malloc0(sizeof(CharDriverState)); chr = qemu_chr_alloc();
chr->chr_write = msmouse_chr_write; chr->chr_write = msmouse_chr_write;
chr->chr_close = msmouse_chr_close; chr->chr_close = msmouse_chr_close;
chr->explicit_be_open = true; chr->explicit_be_open = true;
......
...@@ -88,6 +88,15 @@ struct CharDriverState { ...@@ -88,6 +88,15 @@ struct CharDriverState {
QTAILQ_ENTRY(CharDriverState) next; QTAILQ_ENTRY(CharDriverState) next;
}; };
/**
* @qemu_chr_alloc:
*
* Allocate and initialize a new CharDriverState.
*
* Returns: a newly allocated CharDriverState.
*/
CharDriverState *qemu_chr_alloc(void);
/** /**
* @qemu_chr_new_from_opts: * @qemu_chr_new_from_opts:
* *
......
...@@ -91,6 +91,12 @@ ...@@ -91,6 +91,12 @@
static QTAILQ_HEAD(CharDriverStateHead, CharDriverState) chardevs = static QTAILQ_HEAD(CharDriverStateHead, CharDriverState) chardevs =
QTAILQ_HEAD_INITIALIZER(chardevs); QTAILQ_HEAD_INITIALIZER(chardevs);
CharDriverState *qemu_chr_alloc(void)
{
CharDriverState *chr = g_malloc0(sizeof(CharDriverState));
return chr;
}
void qemu_chr_be_event(CharDriverState *s, int event) void qemu_chr_be_event(CharDriverState *s, int event)
{ {
/* Keep track if the char device is open */ /* Keep track if the char device is open */
...@@ -282,7 +288,7 @@ static CharDriverState *qemu_chr_open_null(void) ...@@ -282,7 +288,7 @@ static CharDriverState *qemu_chr_open_null(void)
{ {
CharDriverState *chr; CharDriverState *chr;
chr = g_malloc0(sizeof(CharDriverState)); chr = qemu_chr_alloc();
chr->chr_write = null_chr_write; chr->chr_write = null_chr_write;
chr->explicit_be_open = true; chr->explicit_be_open = true;
return chr; return chr;
...@@ -570,7 +576,7 @@ static CharDriverState *qemu_chr_open_mux(CharDriverState *drv) ...@@ -570,7 +576,7 @@ static CharDriverState *qemu_chr_open_mux(CharDriverState *drv)
CharDriverState *chr; CharDriverState *chr;
MuxDriver *d; MuxDriver *d;
chr = g_malloc0(sizeof(CharDriverState)); chr = qemu_chr_alloc();
d = g_malloc0(sizeof(MuxDriver)); d = g_malloc0(sizeof(MuxDriver));
chr->opaque = d; chr->opaque = d;
...@@ -945,7 +951,7 @@ static CharDriverState *qemu_chr_open_fd(int fd_in, int fd_out) ...@@ -945,7 +951,7 @@ static CharDriverState *qemu_chr_open_fd(int fd_in, int fd_out)
CharDriverState *chr; CharDriverState *chr;
FDCharDriver *s; FDCharDriver *s;
chr = g_malloc0(sizeof(CharDriverState)); chr = qemu_chr_alloc();
s = g_malloc0(sizeof(FDCharDriver)); s = g_malloc0(sizeof(FDCharDriver));
s->fd_in = io_channel_from_fd(fd_in); s->fd_in = io_channel_from_fd(fd_in);
s->fd_out = io_channel_from_fd(fd_out); s->fd_out = io_channel_from_fd(fd_out);
...@@ -1222,7 +1228,7 @@ static CharDriverState *qemu_chr_open_pty(const char *id, ...@@ -1222,7 +1228,7 @@ static CharDriverState *qemu_chr_open_pty(const char *id,
close(slave_fd); close(slave_fd);
chr = g_malloc0(sizeof(CharDriverState)); chr = qemu_chr_alloc();
chr->filename = g_strdup_printf("pty:%s", pty_name); chr->filename = g_strdup_printf("pty:%s", pty_name);
ret->pty = g_strdup(pty_name); ret->pty = g_strdup(pty_name);
...@@ -1584,7 +1590,7 @@ static CharDriverState *qemu_chr_open_pp_fd(int fd) ...@@ -1584,7 +1590,7 @@ static CharDriverState *qemu_chr_open_pp_fd(int fd)
drv->fd = fd; drv->fd = fd;
drv->mode = IEEE1284_MODE_COMPAT; drv->mode = IEEE1284_MODE_COMPAT;
chr = g_malloc0(sizeof(CharDriverState)); chr = qemu_chr_alloc();
chr->chr_write = null_chr_write; chr->chr_write = null_chr_write;
chr->chr_ioctl = pp_ioctl; chr->chr_ioctl = pp_ioctl;
chr->chr_close = pp_close; chr->chr_close = pp_close;
...@@ -1639,7 +1645,7 @@ static CharDriverState *qemu_chr_open_pp_fd(int fd) ...@@ -1639,7 +1645,7 @@ static CharDriverState *qemu_chr_open_pp_fd(int fd)
{ {
CharDriverState *chr; CharDriverState *chr;
chr = g_malloc0(sizeof(CharDriverState)); chr = qemu_chr_alloc();
chr->opaque = (void *)(intptr_t)fd; chr->opaque = (void *)(intptr_t)fd;
chr->chr_write = null_chr_write; chr->chr_write = null_chr_write;
chr->chr_ioctl = pp_ioctl; chr->chr_ioctl = pp_ioctl;
...@@ -1863,7 +1869,7 @@ static CharDriverState *qemu_chr_open_win_path(const char *filename) ...@@ -1863,7 +1869,7 @@ static CharDriverState *qemu_chr_open_win_path(const char *filename)
CharDriverState *chr; CharDriverState *chr;
WinCharState *s; WinCharState *s;
chr = g_malloc0(sizeof(CharDriverState)); chr = qemu_chr_alloc();
s = g_malloc0(sizeof(WinCharState)); s = g_malloc0(sizeof(WinCharState));
chr->opaque = s; chr->opaque = s;
chr->chr_write = win_chr_write; chr->chr_write = win_chr_write;
...@@ -1962,7 +1968,7 @@ static CharDriverState *qemu_chr_open_pipe(ChardevHostdev *opts) ...@@ -1962,7 +1968,7 @@ static CharDriverState *qemu_chr_open_pipe(ChardevHostdev *opts)
CharDriverState *chr; CharDriverState *chr;
WinCharState *s; WinCharState *s;
chr = g_malloc0(sizeof(CharDriverState)); chr = qemu_chr_alloc();
s = g_malloc0(sizeof(WinCharState)); s = g_malloc0(sizeof(WinCharState));
chr->opaque = s; chr->opaque = s;
chr->chr_write = win_chr_write; chr->chr_write = win_chr_write;
...@@ -1981,7 +1987,7 @@ static CharDriverState *qemu_chr_open_win_file(HANDLE fd_out) ...@@ -1981,7 +1987,7 @@ static CharDriverState *qemu_chr_open_win_file(HANDLE fd_out)
CharDriverState *chr; CharDriverState *chr;
WinCharState *s; WinCharState *s;
chr = g_malloc0(sizeof(CharDriverState)); chr = qemu_chr_alloc();
s = g_malloc0(sizeof(WinCharState)); s = g_malloc0(sizeof(WinCharState));
s->hcom = fd_out; s->hcom = fd_out;
chr->opaque = s; chr->opaque = s;
...@@ -2137,7 +2143,7 @@ static CharDriverState *qemu_chr_open_stdio(ChardevStdio *opts) ...@@ -2137,7 +2143,7 @@ static CharDriverState *qemu_chr_open_stdio(ChardevStdio *opts)
DWORD dwMode; DWORD dwMode;
int is_console = 0; int is_console = 0;
chr = g_malloc0(sizeof(CharDriverState)); chr = qemu_chr_alloc();
stdio = g_malloc0(sizeof(WinStdioCharState)); stdio = g_malloc0(sizeof(WinStdioCharState));
stdio->hStdIn = GetStdHandle(STD_INPUT_HANDLE); stdio->hStdIn = GetStdHandle(STD_INPUT_HANDLE);
...@@ -2299,7 +2305,7 @@ static CharDriverState *qemu_chr_open_udp_fd(int fd) ...@@ -2299,7 +2305,7 @@ static CharDriverState *qemu_chr_open_udp_fd(int fd)
CharDriverState *chr = NULL; CharDriverState *chr = NULL;
NetCharDriver *s = NULL; NetCharDriver *s = NULL;
chr = g_malloc0(sizeof(CharDriverState)); chr = qemu_chr_alloc();
s = g_malloc0(sizeof(NetCharDriver)); s = g_malloc0(sizeof(NetCharDriver));
s->fd = fd; s->fd = fd;
...@@ -2850,7 +2856,7 @@ static CharDriverState *qemu_chr_open_socket_fd(int fd, bool do_nodelay, ...@@ -2850,7 +2856,7 @@ static CharDriverState *qemu_chr_open_socket_fd(int fd, bool do_nodelay,
return NULL; return NULL;
} }
chr = g_malloc0(sizeof(CharDriverState)); chr = qemu_chr_alloc();
s = g_malloc0(sizeof(TCPCharDriver)); s = g_malloc0(sizeof(TCPCharDriver));
s->connected = 0; s->connected = 0;
...@@ -3040,7 +3046,7 @@ static CharDriverState *qemu_chr_open_ringbuf(ChardevRingbuf *opts, ...@@ -3040,7 +3046,7 @@ static CharDriverState *qemu_chr_open_ringbuf(ChardevRingbuf *opts,
CharDriverState *chr; CharDriverState *chr;
RingBufCharDriver *d; RingBufCharDriver *d;
chr = g_malloc0(sizeof(CharDriverState)); chr = qemu_chr_alloc();
d = g_malloc(sizeof(*d)); d = g_malloc(sizeof(*d));
d->size = opts->has_size ? opts->size : 65536; d->size = opts->has_size ? opts->size : 65536;
......
...@@ -268,7 +268,7 @@ static CharDriverState *chr_open(const char *subtype, ...@@ -268,7 +268,7 @@ static CharDriverState *chr_open(const char *subtype,
CharDriverState *chr; CharDriverState *chr;
SpiceCharDriver *s; SpiceCharDriver *s;
chr = g_malloc0(sizeof(CharDriverState)); chr = qemu_chr_alloc();
s = g_malloc0(sizeof(SpiceCharDriver)); s = g_malloc0(sizeof(SpiceCharDriver));
s->chr = chr; s->chr = chr;
s->active = false; s->active = false;
......
...@@ -1821,7 +1821,7 @@ static CharDriverState *text_console_init(ChardevVC *vc) ...@@ -1821,7 +1821,7 @@ static CharDriverState *text_console_init(ChardevVC *vc)
unsigned width = 0; unsigned width = 0;
unsigned height = 0; unsigned height = 0;
chr = g_malloc0(sizeof(CharDriverState)); chr = qemu_chr_alloc();
if (vc->has_width) { if (vc->has_width) {
width = vc->width; width = vc->width;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment