From: Amit Shah <amit.shah@redhat.com>
To: virtualization@lists.linux-foundation.org
Cc: Amit Shah <amit.shah@redhat.com>, quintela@redhat.com, mst@redhat.com
Subject: [PATCH 4/6] virtio: console: Separate out get_config in a separate function
Date: Fri, 19 Mar 2010 17:36:46 +0530 [thread overview]
Message-ID: <1269000408-29962-5-git-send-email-amit.shah@redhat.com> (raw)
In-Reply-To: <1269000408-29962-4-git-send-email-amit.shah@redhat.com>
Getting config information is done in probe() as well as
config_work_handler().
Separate it out so that we only code it once.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
drivers/char/virtio_console.c | 85 +++++++++++++++++++++++------------------
1 files changed, 48 insertions(+), 37 deletions(-)
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index dc15c92..9f2cbf0 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -1227,6 +1227,46 @@ static u32 get_ports_map_size(u32 max_nr_ports)
return sizeof(u32) * ((max_nr_ports + 31)/ 32);
}
+static struct virtio_console_config *get_config(struct virtio_device *vdev,
+ bool multiport)
+{
+ struct virtio_console_config *config;
+ u32 max_nr_ports;
+
+ if (!multiport) {
+ config = kmalloc(sizeof(struct virtio_console_config),
+ GFP_KERNEL);
+ if (!config)
+ return NULL;
+
+ config->max_nr_ports = 1;
+ return config;
+ }
+
+ vdev->config->get(vdev, offsetof(struct virtio_console_config,
+ max_nr_ports),
+ &max_nr_ports, sizeof(max_nr_ports));
+
+ /*
+ * We have a variable-sized config space that's dependent on
+ * the maximum number of ports a guest can have. So we first
+ * get the max number of ports we can have and then allocate
+ * the config space
+ */
+ config = kmalloc(sizeof(struct virtio_console_config)
+ + get_ports_map_size(max_nr_ports),
+ GFP_KERNEL);
+ if (!config)
+ return NULL;
+
+ config->max_nr_ports = max_nr_ports;
+ vdev->config->get(vdev, offsetof(struct virtio_console_config,
+ ports_map),
+ config->ports_map,
+ get_ports_map_size(max_nr_ports));
+ return config;
+}
+
/*
* The workhandler for config-space updates.
*
@@ -1394,49 +1434,20 @@ static int __devinit virtcons_probe(struct virtio_device *vdev)
goto free;
}
+ multiport = false;
if (virtio_has_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT)) {
- u32 max_nr_ports;
-
multiport = true;
vdev->features[0] |= 1 << VIRTIO_CONSOLE_F_MULTIPORT;
- vdev->config->get(vdev, offsetof(struct virtio_console_config,
- max_nr_ports),
- &max_nr_ports, sizeof(max_nr_ports));
- /*
- * We have a variable-sized config space that's
- * dependent on the maximum number of ports a guest
- * can have. So we first get the max number of ports
- * we can have and then allocate the config space
- */
- portdev->config = kmalloc(sizeof(struct virtio_console_config)
- + get_ports_map_size(max_nr_ports),
- GFP_KERNEL);
- if (!portdev->config) {
- err = -ENOMEM;
- goto free_chrdev;
- }
-
- portdev->config->max_nr_ports = max_nr_ports;
- vdev->config->get(vdev, offsetof(struct virtio_console_config,
- ports_map),
- portdev->config->ports_map,
- get_ports_map_size(max_nr_ports));
- } else {
- multiport = false;
-
- portdev->config = kmalloc(sizeof(struct virtio_console_config),
- GFP_KERNEL);
- if (!portdev->config) {
- err = -ENOMEM;
- goto free_chrdev;
- }
-
- portdev->config->max_nr_ports = 1;
+ /* Let the Host know we support multiple ports.*/
+ vdev->config->finalize_features(vdev);
}
- /* Let the Host know we support multiple ports.*/
- vdev->config->finalize_features(vdev);
+ portdev->config = get_config(vdev, multiport);
+ if (!portdev->config) {
+ err = -ENOMEM;
+ goto free_chrdev;
+ }
err = init_vqs(portdev);
if (err < 0) {
--
1.6.2.5
next prev parent reply other threads:[~2010-03-19 12:06 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-19 12:06 [PATCH 0/6] virtio: console: Fixes, abi update Amit Shah
2010-03-19 12:06 ` [PATCH 1/6] virtio: console: Generate a kobject CHANGE event on adding 'name' attribute Amit Shah
2010-03-19 12:06 ` [PATCH 2/6] virtio: console: Check if port is valid in resize_console Amit Shah
2010-03-19 12:06 ` [PATCH 3/6] virtio: console: Switch to using a port bitmap for port discovery Amit Shah
2010-03-19 12:06 ` Amit Shah [this message]
2010-03-19 12:06 ` [PATCH 5/6] virtio: console: Handle hot-plug/unplug config actions Amit Shah
2010-03-19 12:06 ` [PATCH 6/6] virtio: console: Remove hot-unplug control message Amit Shah
2010-03-21 11:29 ` [PATCH 3/6] virtio: console: Switch to using a port bitmap for port discovery Michael S. Tsirkin
2010-03-22 4:04 ` Amit Shah
2010-03-22 8:53 ` Michael S. Tsirkin
2010-03-22 9:45 ` Amit Shah
2010-03-22 12:16 ` Michael S. Tsirkin
2010-03-22 12:31 ` Amit Shah
2010-03-21 11:44 ` [PATCH 0/6] virtio: console: Fixes, abi update Michael S. Tsirkin
2010-03-22 10:44 ` Amit Shah
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1269000408-29962-5-git-send-email-amit.shah@redhat.com \
--to=amit.shah@redhat.com \
--cc=mst@redhat.com \
--cc=quintela@redhat.com \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).