summaryrefslogtreecommitdiff
path: root/chardev
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2016-12-12 13:41:40 +0300
committerMarc-André Lureau <marcandre.lureau@redhat.com>2017-01-31 23:31:20 +0400
commiteb314a9497dbbbd14795a6cdba27eb3131ee7e25 (patch)
tree6ec49e35c54db8228e76374bbd1be9cc4f8c5a0e /chardev
parent32d955a4221535a1a2d8730e0520561ad7531efd (diff)
downloadqemu-eb314a9497dbbbd14795a6cdba27eb3131ee7e25.tar.gz
char: make null_chr_write() the default method
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 <marcandre.lureau@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'chardev')
-rw-r--r--chardev/char.c21
1 files 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
}