Commit c59dbcadd5d125ba40595612dc91ab18924164d3

Authored by Jeff Dike
Committed by Linus Torvalds
1 parent e99525f970

uml: fix console writing bugs

The previous console cleanup patch switched generic_read and generic_write
from calling os_{read,write}_file to calling read and write directly.  Because
the calling convention is different, they now need to get any error from errno
rather than the return value.  I did this for generic_read, but forgot about
generic_write.

While chasing some output corruption, I noticed that line_write was
unnecessarily calling flush_buffer, and deleted it.  I don't understand why,
but the corruption disappeared.  This is unneeded because there already is a
perfectly good mechanism for finding out when the host output device has some
room to write data - there is an interrupt that comes in when writes can
happen again.  line_write calling flush_buffer seemed to just be an attempt to
opportunistically get some data out to the host.

I also made write_chan short-circuit calling into the host-level code for
zero-length writes.  Calling libc write with a length of zero conflated write
not being able to write anything with asking it not to write anything.  Better
to just cut it off as soon as possible.

Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 3 changed files with 16 additions and 7 deletions Side-by-side Diff

arch/um/drivers/chan_kern.c
... ... @@ -291,6 +291,9 @@
291 291 struct chan *chan = NULL;
292 292 int n, ret = 0;
293 293  
  294 + if (len == 0)
  295 + return 0;
  296 +
294 297 list_for_each(ele, chans) {
295 298 chan = list_entry(ele, struct chan, list);
296 299 if (!chan->output || (chan->ops->write == NULL))
arch/um/drivers/chan_user.c
... ... @@ -38,7 +38,16 @@
38 38  
39 39 int generic_write(int fd, const char *buf, int n, void *unused)
40 40 {
41   - return write(fd, buf, n);
  41 + int err;
  42 +
  43 + err = write(fd, buf, n);
  44 + if (err > 0)
  45 + return err;
  46 + else if (errno == EAGAIN)
  47 + return 0;
  48 + else if (err == 0)
  49 + return -EIO;
  50 + return -errno;
42 51 }
43 52  
44 53 int generic_window_size(int fd, void *unused, unsigned short *rows_out,
arch/um/drivers/line.c
... ... @@ -216,18 +216,15 @@
216 216 {
217 217 struct line *line = tty->driver_data;
218 218 unsigned long flags;
219   - int n, err, ret = 0;
  219 + int n, ret = 0;
220 220  
221 221 if(tty->stopped)
222 222 return 0;
223 223  
224 224 spin_lock_irqsave(&line->lock, flags);
225   - if (line->head != line->tail) {
  225 + if (line->head != line->tail)
226 226 ret = buffer_data(line, buf, len);
227   - err = flush_buffer(line);
228   - if (err <= 0 && (err != -EAGAIN || !ret))
229   - ret = err;
230   - } else {
  227 + else {
231 228 n = write_chan(&line->chan_list, buf, len,
232 229 line->driver->write_irq);
233 230 if (n < 0) {