History

fix a kmap leak in virtio_console

While we are at it, don't do kmap() under kmap_atomic(), *especially* for a page we'd allocated with GFP_KERNEL. It's spelled "page_address", and had that been more than that, we'd have a real trouble - kmap_high() can block, and doing that while holding kmap_atomic() is a Bad Idea(tm).

Al Viro committed 12 years ago

Commit c9efe511 parent d311d791 file · +3 −6Browse files

Unified · Split

drivers/char/virtio_console.c+3−6
@@ -890,12 +890,10 @@ static int pipe_to_sg(struct pipe_inode_info *pipe, struct pipe_buffer *buf, · 889 unmodified lines
890890 } else {
891891 /* Failback to copying a page */
892892 struct page *page = alloc_page(GFP_KERNEL);
893− char *src = buf->ops->map(pipe, buf, 1);
894− char *dst;
893+ char *src;
895894
896895 if (!page)
897896 return -ENOMEM;
898− dst = kmap(page);
899897
900898 offset = sd->pos & ~PAGE_MASK;
901899
@@ -903,9 +901,8 @@ static int pipe_to_sg(struct pipe_inode_info *pipe, struct pipe_buffer *buf, · 1 unmodified line
903901 if (len + offset > PAGE_SIZE)
904902 len = PAGE_SIZE - offset;
905903
906− memcpy(dst + offset, src + buf->offset, len);
907−
908− kunmap(page);
904+ src = buf->ops->map(pipe, buf, 1);
905+ memcpy(page_address(page) + offset, src + buf->offset, len);
909906 buf->ops->unmap(pipe, buf, src);
910907
911908 sg_set_page(&(sgl->sg[sgl->n]), page, len, offset);