From eb314a9497dbbbd14795a6cdba27eb3131ee7e25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Mon, 12 Dec 2016 13:41:40 +0300 Subject: [PATCH] char: make null_chr_write() the default method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All chardev must implement chr_write(), but parallel and null chardev both use null_chr_write(). Move it to the base class, so we don't need to export the function when splitting the chardev in respective files. Signed-off-by: Marc-André Lureau Reviewed-by: Eric Blake --- chardev/char.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/chardev/char.c b/chardev/char.c index 15f4a853bc..ee6ceb3471 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -522,6 +522,18 @@ static void char_init(Object *obj) qemu_mutex_init(&chr->chr_write_lock); } +static int null_chr_write(Chardev *chr, const uint8_t *buf, int len) +{ + return len; +} + +static void char_class_init(ObjectClass *oc, void *data) +{ + ChardevClass *cc = CHARDEV_CLASS(oc); + + cc->chr_write = null_chr_write; +} + static void char_finalize(Object *obj) { Chardev *chr = CHARDEV(obj); @@ -545,13 +557,9 @@ static const TypeInfo char_type_info = { .instance_finalize = char_finalize, .abstract = true, .class_size = sizeof(ChardevClass), + .class_init = char_class_init, }; -static int null_chr_write(Chardev *chr, const uint8_t *buf, int len) -{ - return len; -} - static void null_chr_open(Chardev *chr, ChardevBackend *backend, bool *be_opened, @@ -565,7 +573,6 @@ static void char_null_class_init(ObjectClass *oc, void *data) ChardevClass *cc = CHARDEV_CLASS(oc); cc->open = null_chr_open; - cc->chr_write = null_chr_write; } static const TypeInfo char_null_type_info = { @@ -4712,10 +4719,8 @@ static void char_parallel_class_init(ObjectClass *oc, void *data) cc->parse = qemu_chr_parse_parallel; cc->open = qmp_chardev_open_parallel; #if defined(__linux__) - cc->chr_write = null_chr_write; cc->chr_ioctl = pp_ioctl; #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) - cc->chr_write = null_chr_write; cc->chr_ioctl = pp_ioctl; #endif }