Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751965AbbETFOD (ORCPT ); Wed, 20 May 2015 01:14:03 -0400 Received: from mail.kernel.org ([198.145.29.136]:32865 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751182AbbETFOB (ORCPT ); Wed, 20 May 2015 01:14:01 -0400 From: Ming Lin To: Jens Axboe Cc: Christoph Hellwig , linux-kernel@vger.kernel.org Subject: [PATCH RESEND] bio: switch to iov_iter_{npages,alignment} Date: Tue, 19 May 2015 22:13:58 -0700 Message-Id: <1432098838-3241-1-git-send-email-mlin@kernel.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2199 Lines: 82 Reviewed-by: Christoph Hellwig Signed-off-by: Ming Lin --- block/bio.c | 45 +++++++-------------------------------------- 1 file changed, 7 insertions(+), 38 deletions(-) diff --git a/block/bio.c b/block/bio.c index ae31cdb..e6bd9c2 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1129,29 +1129,14 @@ struct bio *bio_copy_user_iov(struct request_queue *q, struct bio_map_data *bmd; struct page *page; struct bio *bio; - int i, ret; + int uninitialized_var(i), ret; int nr_pages = 0; unsigned int len = iter->count; unsigned int offset = map_data ? map_data->offset & ~PAGE_MASK : 0; - for (i = 0; i < iter->nr_segs; i++) { - unsigned long uaddr; - unsigned long end; - unsigned long start; - - uaddr = (unsigned long) iter->iov[i].iov_base; - end = (uaddr + iter->iov[i].iov_len + PAGE_SIZE - 1) - >> PAGE_SHIFT; - start = uaddr >> PAGE_SHIFT; - - /* - * Overflow, abort - */ - if (end < start) - return ERR_PTR(-EINVAL); - - nr_pages += end - start; - } + nr_pages = iov_iter_npages(iter, INT_MAX); + if (!nr_pages) + return ERR_PTR(-EINVAL); if (offset) nr_pages++; @@ -1263,26 +1248,10 @@ struct bio *bio_map_user_iov(struct request_queue *q, struct iov_iter i; struct iovec iov; - iov_for_each(iov, i, *iter) { - unsigned long uaddr = (unsigned long) iov.iov_base; - unsigned long len = iov.iov_len; - unsigned long end = (uaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT; - unsigned long start = uaddr >> PAGE_SHIFT; - - /* - * Overflow, abort - */ - if (end < start) - return ERR_PTR(-EINVAL); - - nr_pages += end - start; - /* - * buffer must be aligned to at least hardsector size for now - */ - if (uaddr & queue_dma_alignment(q)) - return ERR_PTR(-EINVAL); - } + if (iov_iter_alignment(iter) & queue_dma_alignment(q)) + return ERR_PTR(-EINVAL); + nr_pages = iov_iter_npages(iter, INT_MAX); if (!nr_pages) return ERR_PTR(-EINVAL); -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/