diff --git a/page-pipe.c b/page-pipe.c index 18d5a68f9..010da2470 100644 --- a/page-pipe.c +++ b/page-pipe.c @@ -19,6 +19,12 @@ static inline bool iov_grow_page(struct iovec *iov, unsigned long addr) return false; } +static inline void iov_init(struct iovec *iov, unsigned long addr) +{ + iov->iov_base = (void *)addr; + iov->iov_len = PAGE_SIZE; +} + static int page_pipe_grow(struct page_pipe *pp) { struct page_pipe_buf *ppb; @@ -150,9 +156,7 @@ static inline int try_add_page_to(struct page_pipe *pp, struct page_pipe_buf *pp pr_debug("Add iov to page pipe (%u iovs, %u/%u total)\n", ppb->nr_segs, pp->free_iov, pp->nr_iovs); - ppb->iov[ppb->nr_segs].iov_base = (void *)addr; - ppb->iov[ppb->nr_segs].iov_len = PAGE_SIZE; - ppb->nr_segs++; + iov_init(&ppb->iov[ppb->nr_segs++], addr); pp->free_iov++; BUG_ON(pp->free_iov > pp->nr_iovs); out: @@ -187,8 +191,6 @@ int page_pipe_add_page(struct page_pipe *pp, unsigned long addr) int page_pipe_add_hole(struct page_pipe *pp, unsigned long addr) { - struct iovec *iov; - if (pp->free_hole >= pp->nr_holes) { pp->holes = xrealloc(pp->holes, (pp->nr_holes + PP_HOLES_BATCH) * sizeof(struct iovec)); @@ -202,10 +204,7 @@ int page_pipe_add_hole(struct page_pipe *pp, unsigned long addr) iov_grow_page(&pp->holes[pp->free_hole - 1], addr)) goto out; - iov = &pp->holes[pp->free_hole]; - iov->iov_base = (void *)addr; - iov->iov_len = PAGE_SIZE; - pp->free_hole++; + iov_init(&pp->holes[pp->free_hole++], addr); out: return 0; }