From patchwork Mon Jun 23 16:36:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 363042 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D6A4B14007C for ; Tue, 24 Jun 2014 02:46:47 +1000 (EST) Received: from localhost ([::1]:54895 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz7OI-0007BP-3Z for incoming@patchwork.ozlabs.org; Mon, 23 Jun 2014 12:46:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52489) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz7FK-00044m-Jw for qemu-devel@nongnu.org; Mon, 23 Jun 2014 12:37:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wz7FC-00045c-Rd for qemu-devel@nongnu.org; Mon, 23 Jun 2014 12:37:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31756) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz7FC-00045F-J5 for qemu-devel@nongnu.org; Mon, 23 Jun 2014 12:37:22 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s5NGbEju023665 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Jun 2014 12:37:15 -0400 Received: from localhost (ovpn-113-42.phx2.redhat.com [10.3.113.42]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s5NGbEgn021840; Mon, 23 Jun 2014 12:37:14 -0400 From: Luiz Capitulino To: peter.maydell@linaro.org Date: Mon, 23 Jun 2014 12:36:38 -0400 Message-Id: <1403541403-16468-39-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1403541403-16468-1-git-send-email-lcapitulino@redhat.com> References: <1403541403-16468-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org, anthony@codemonkey.ws Subject: [Qemu-devel] [PULL 38/43] qemu-char: introduce qemu_chr_alloc X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Paolo Bonzini The next patch will modify this function to initialize state that is common to all backends. Reviewed-by: Fam Zheng Signed-off-by: Paolo Bonzini Signed-off-by: Luiz Capitulino --- backends/baum.c | 2 +- backends/msmouse.c | 2 +- include/sysemu/char.h | 9 +++++++++ qemu-char.c | 32 +++++++++++++++++++------------- spice-qemu-char.c | 2 +- ui/console.c | 2 +- 6 files changed, 32 insertions(+), 17 deletions(-) diff --git a/backends/baum.c b/backends/baum.c index 759003f..796512d 100644 --- a/backends/baum.c +++ b/backends/baum.c @@ -574,7 +574,7 @@ CharDriverState *chr_baum_init(void) int tty; baum = g_malloc0(sizeof(BaumDriverState)); - baum->chr = chr = g_malloc0(sizeof(CharDriverState)); + baum->chr = chr = qemu_chr_alloc(); chr->opaque = baum; chr->chr_write = baum_write; diff --git a/backends/msmouse.c b/backends/msmouse.c index c0dbfcd..650a531 100644 --- a/backends/msmouse.c +++ b/backends/msmouse.c @@ -67,7 +67,7 @@ CharDriverState *qemu_chr_open_msmouse(void) { CharDriverState *chr; - chr = g_malloc0(sizeof(CharDriverState)); + chr = qemu_chr_alloc(); chr->chr_write = msmouse_chr_write; chr->chr_close = msmouse_chr_close; chr->explicit_be_open = true; diff --git a/include/sysemu/char.h b/include/sysemu/char.h index 672ed39..bd2b62d 100644 --- a/include/sysemu/char.h +++ b/include/sysemu/char.h @@ -89,6 +89,15 @@ struct CharDriverState { }; /** + * @qemu_chr_alloc: + * + * Allocate and initialize a new CharDriverState. + * + * Returns: a newly allocated CharDriverState. + */ +CharDriverState *qemu_chr_alloc(void); + +/** * @qemu_chr_new_from_opts: * * Create a new character backend from a QemuOpts list. diff --git a/qemu-char.c b/qemu-char.c index e4eb985..7e4bd90 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -91,6 +91,12 @@ static QTAILQ_HEAD(CharDriverStateHead, CharDriverState) 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) { /* Keep track if the char device is open */ @@ -282,7 +288,7 @@ static CharDriverState *qemu_chr_open_null(void) { CharDriverState *chr; - chr = g_malloc0(sizeof(CharDriverState)); + chr = qemu_chr_alloc(); chr->chr_write = null_chr_write; chr->explicit_be_open = true; return chr; @@ -570,7 +576,7 @@ static CharDriverState *qemu_chr_open_mux(CharDriverState *drv) CharDriverState *chr; MuxDriver *d; - chr = g_malloc0(sizeof(CharDriverState)); + chr = qemu_chr_alloc(); d = g_malloc0(sizeof(MuxDriver)); chr->opaque = d; @@ -945,7 +951,7 @@ static CharDriverState *qemu_chr_open_fd(int fd_in, int fd_out) CharDriverState *chr; FDCharDriver *s; - chr = g_malloc0(sizeof(CharDriverState)); + chr = qemu_chr_alloc(); s = g_malloc0(sizeof(FDCharDriver)); s->fd_in = io_channel_from_fd(fd_in); s->fd_out = io_channel_from_fd(fd_out); @@ -1222,7 +1228,7 @@ static CharDriverState *qemu_chr_open_pty(const char *id, close(slave_fd); - chr = g_malloc0(sizeof(CharDriverState)); + chr = qemu_chr_alloc(); chr->filename = g_strdup_printf("pty:%s", pty_name); ret->pty = g_strdup(pty_name); @@ -1584,7 +1590,7 @@ static CharDriverState *qemu_chr_open_pp_fd(int fd) drv->fd = fd; drv->mode = IEEE1284_MODE_COMPAT; - chr = g_malloc0(sizeof(CharDriverState)); + chr = qemu_chr_alloc(); chr->chr_write = null_chr_write; chr->chr_ioctl = pp_ioctl; chr->chr_close = pp_close; @@ -1639,7 +1645,7 @@ static CharDriverState *qemu_chr_open_pp_fd(int fd) { CharDriverState *chr; - chr = g_malloc0(sizeof(CharDriverState)); + chr = qemu_chr_alloc(); chr->opaque = (void *)(intptr_t)fd; chr->chr_write = null_chr_write; chr->chr_ioctl = pp_ioctl; @@ -1863,7 +1869,7 @@ static CharDriverState *qemu_chr_open_win_path(const char *filename) CharDriverState *chr; WinCharState *s; - chr = g_malloc0(sizeof(CharDriverState)); + chr = qemu_chr_alloc(); s = g_malloc0(sizeof(WinCharState)); chr->opaque = s; chr->chr_write = win_chr_write; @@ -1962,7 +1968,7 @@ static CharDriverState *qemu_chr_open_pipe(ChardevHostdev *opts) CharDriverState *chr; WinCharState *s; - chr = g_malloc0(sizeof(CharDriverState)); + chr = qemu_chr_alloc(); s = g_malloc0(sizeof(WinCharState)); chr->opaque = s; chr->chr_write = win_chr_write; @@ -1981,7 +1987,7 @@ static CharDriverState *qemu_chr_open_win_file(HANDLE fd_out) CharDriverState *chr; WinCharState *s; - chr = g_malloc0(sizeof(CharDriverState)); + chr = qemu_chr_alloc(); s = g_malloc0(sizeof(WinCharState)); s->hcom = fd_out; chr->opaque = s; @@ -2137,7 +2143,7 @@ static CharDriverState *qemu_chr_open_stdio(ChardevStdio *opts) DWORD dwMode; int is_console = 0; - chr = g_malloc0(sizeof(CharDriverState)); + chr = qemu_chr_alloc(); stdio = g_malloc0(sizeof(WinStdioCharState)); stdio->hStdIn = GetStdHandle(STD_INPUT_HANDLE); @@ -2299,7 +2305,7 @@ static CharDriverState *qemu_chr_open_udp_fd(int fd) CharDriverState *chr = NULL; NetCharDriver *s = NULL; - chr = g_malloc0(sizeof(CharDriverState)); + chr = qemu_chr_alloc(); s = g_malloc0(sizeof(NetCharDriver)); s->fd = fd; @@ -2850,7 +2856,7 @@ static CharDriverState *qemu_chr_open_socket_fd(int fd, bool do_nodelay, return NULL; } - chr = g_malloc0(sizeof(CharDriverState)); + chr = qemu_chr_alloc(); s = g_malloc0(sizeof(TCPCharDriver)); s->connected = 0; @@ -3040,7 +3046,7 @@ static CharDriverState *qemu_chr_open_ringbuf(ChardevRingbuf *opts, CharDriverState *chr; RingBufCharDriver *d; - chr = g_malloc0(sizeof(CharDriverState)); + chr = qemu_chr_alloc(); d = g_malloc(sizeof(*d)); d->size = opts->has_size ? opts->size : 65536; diff --git a/spice-qemu-char.c b/spice-qemu-char.c index 6624559..4518a4d 100644 --- a/spice-qemu-char.c +++ b/spice-qemu-char.c @@ -268,7 +268,7 @@ static CharDriverState *chr_open(const char *subtype, CharDriverState *chr; SpiceCharDriver *s; - chr = g_malloc0(sizeof(CharDriverState)); + chr = qemu_chr_alloc(); s = g_malloc0(sizeof(SpiceCharDriver)); s->chr = chr; s->active = false; diff --git a/ui/console.c b/ui/console.c index 7dc4c14..ab84549 100644 --- a/ui/console.c +++ b/ui/console.c @@ -1821,7 +1821,7 @@ static CharDriverState *text_console_init(ChardevVC *vc) unsigned width = 0; unsigned height = 0; - chr = g_malloc0(sizeof(CharDriverState)); + chr = qemu_chr_alloc(); if (vc->has_width) { width = vc->width;