[PATCH] hvc_console: Separate the NUL character filtering from get_hvc_chars
[linux-2.6.git] / drivers / char / hvc_vio.c
index d2928f90ab5149d3f64f4ad2404d90040aa5115b..60bb9152b832fdc3f5021ae0af310dd71b1f275b 100644 (file)
@@ -43,6 +43,33 @@ static struct vio_device_id hvc_driver_table[] __devinitdata = {
 };
 MODULE_DEVICE_TABLE(vio, hvc_driver_table);
 
+static int filtered_get_chars(uint32_t vtermno, char *buf, int count)
+{
+       unsigned long got;
+       int i;
+
+       got = hvc_get_chars(vtermno, buf, count);
+
+       /*
+        * Work around a HV bug where it gives us a null
+        * after every \r.  -- paulus
+        */
+       for (i = 1; i < got; ++i) {
+               if (buf[i] == 0 && buf[i-1] == '\r') {
+                       --got;
+                       if (i < got)
+                               memmove(&buf[i], &buf[i+1],
+                                       got - i);
+               }
+       }
+       return got;
+}
+
+static struct hv_ops hvc_get_put_ops = {
+       .get_chars = filtered_get_chars,
+       .put_chars = hvc_put_chars,
+};
+
 static int __devinit hvc_vio_probe(struct vio_dev *vdev,
                                const struct vio_device_id *id)
 {
@@ -52,7 +79,7 @@ static int __devinit hvc_vio_probe(struct vio_dev *vdev,
        if (!vdev || !id)
                return -EPERM;
 
-       hp = hvc_alloc(vdev->unit_address, vdev->irq);
+       hp = hvc_alloc(vdev->unit_address, vdev->irq, &hvc_get_put_ops);
        if (IS_ERR(hp))
                return PTR_ERR(hp);
        dev_set_drvdata(&vdev->dev, hp);
@@ -115,7 +142,7 @@ static int hvc_find_vtys(void)
                        continue;
 
                if (device_is_compatible(vty, "hvterm1")) {
-                       hvc_instantiate(*vtermno, num_found);
+                       hvc_instantiate(*vtermno, num_found, &hvc_get_put_ops);
                        ++num_found;
                }
        }