Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758520AbbDXWpk (ORCPT ); Fri, 24 Apr 2015 18:45:40 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:23447 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755263AbbDXWpg (ORCPT ); Fri, 24 Apr 2015 18:45:36 -0400 X-AuditID: cbfee61b-f79536d000000f1f-b6-553ac78ecb4c From: Ming Lin To: Jens Axboe Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , Al Viro , Kent Overstreet , Ming Lin Subject: [PATCH] bio: switch to iov_iter_{npages,alignment} Date: Fri, 24 Apr 2015 15:45:23 -0700 Message-id: <1429915523-21879-1-git-send-email-mlin@kernel.org> X-Mailer: git-send-email 1.9.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJJMWRmVeSWpSXmKPExsVy+t9jQd2+41ahBlNXiVisvtvPZnF6wiIm iyNNVRaXd81hszi/7SSrxfm/x1kd2Dx2zrrL7rF5hZbH5bOlHptWdbJ5fN4k57HpyVumALYo LpuU1JzMstQifbsEroybL3QLDvFXfH58kamBsY2ni5GTQ0LARGLJgTYWCFtM4sK99WxdjFwc QgLTGSX6Nixmh3B+Mkq87nzLDFLFJqAgcXDdBiYQWwTI7vm9EqyDWWA7o0TzpzY2kISwgLXE jwc9jCA2i4CqxJfFp1lBbF4Be4nbz+ZDrZOTOHlsMusERu4FjAyrGEVTC5ILipPSc430ihNz i0vz0vWS83M3MYID5Jn0DsZVDRaHGAU4GJV4eB1mWYYKsSaWFVfmHmKU4GBWEuHl77UKFeJN SaysSi3Kjy8qzUktPsQozcGiJM47R1cuVEggPbEkNTs1tSC1CCbLxMEp1cBYfqLk3YT6fUuO KbjpJrw2ZH4zISwzbP1j6/ZTO11usM7I7el8dfv/ws1PE55fvTatMT/MPiJKS1EzRdp9R93F yAky74oSXiybe6br1dmp22aw3uj5+rjHZMPcj68SMhZ/mLM+VuCY1xuLzDPHDnRdsxSIerWL /SVXylztCV++PYxddf6GVnDYFyWW4oxEQy3mouJEAKZ/Q8QMAgAA Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2155 Lines: 81 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 05c2864..c3a6468 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1158,29 +1158,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++; @@ -1292,26 +1277,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/