aboutsummaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2015-01-18 10:16:32 -0500
committerJens Axboe <axboe@fb.com>2015-02-05 11:30:42 -0500
commit75c72b8366f35f2e5cf1b841b52095948878b794 (patch)
tree7b7637a0d6dde82baaa894f3244175fd93d8c68c /block
parent26e49cfc7e988a76bf1e55cef0d9e438e5489180 (diff)
block: merge __bio_map_kern into bio_map_kern
This saves a little code, and allow to simplify the error handling. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Ming Lei <tom.leiming@gmail.com> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'block')
-rw-r--r--block/bio.c50
1 files changed, 17 insertions, 33 deletions
diff --git a/block/bio.c b/block/bio.c
index 7d8c6555e3f3..a69a9c9e7c93 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1429,8 +1429,18 @@ static void bio_map_kern_endio(struct bio *bio, int err)
1429 bio_put(bio); 1429 bio_put(bio);
1430} 1430}
1431 1431
1432static struct bio *__bio_map_kern(struct request_queue *q, void *data, 1432/**
1433 unsigned int len, gfp_t gfp_mask) 1433 * bio_map_kern - map kernel address into bio
1434 * @q: the struct request_queue for the bio
1435 * @data: pointer to buffer to map
1436 * @len: length in bytes
1437 * @gfp_mask: allocation flags for bio allocation
1438 *
1439 * Map the kernel address into a bio suitable for io to a block
1440 * device. Returns an error pointer in case of error.
1441 */
1442struct bio *bio_map_kern(struct request_queue *q, void *data, unsigned int len,
1443 gfp_t gfp_mask)
1434{ 1444{
1435 unsigned long kaddr = (unsigned long)data; 1445 unsigned long kaddr = (unsigned long)data;
1436 unsigned long end = (kaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT; 1446 unsigned long end = (kaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
@@ -1454,8 +1464,11 @@ static struct bio *__bio_map_kern(struct request_queue *q, void *data,
1454 bytes = len; 1464 bytes = len;
1455 1465
1456 if (bio_add_pc_page(q, bio, virt_to_page(data), bytes, 1466 if (bio_add_pc_page(q, bio, virt_to_page(data), bytes,
1457 offset) < bytes) 1467 offset) < bytes) {
1458 break; 1468 /* we don't support partial mappings */
1469 bio_put(bio);
1470 return ERR_PTR(-EINVAL);
1471 }
1459 1472
1460 data += bytes; 1473 data += bytes;
1461 len -= bytes; 1474 len -= bytes;
@@ -1465,35 +1478,6 @@ static struct bio *__bio_map_kern(struct request_queue *q, void *data,
1465 bio->bi_end_io = bio_map_kern_endio; 1478 bio->bi_end_io = bio_map_kern_endio;
1466 return bio; 1479 return bio;
1467} 1480}
1468
1469/**
1470 * bio_map_kern - map kernel address into bio
1471 * @q: the struct request_queue for the bio
1472 * @data: pointer to buffer to map
1473 * @len: length in bytes
1474 * @gfp_mask: allocation flags for bio allocation
1475 *
1476 * Map the kernel address into a bio suitable for io to a block
1477 * device. Returns an error pointer in case of error.
1478 */
1479struct bio *bio_map_kern(struct request_queue *q, void *data, unsigned int len,
1480 gfp_t gfp_mask)
1481{
1482 struct bio *bio;
1483
1484 bio = __bio_map_kern(q, data, len, gfp_mask);
1485 if (IS_ERR(bio))
1486 return bio;
1487
1488 if (bio->bi_iter.bi_size == len)
1489 return bio;
1490
1491 /*
1492 * Don't support partial mappings.
1493 */
1494 bio_put(bio);
1495 return ERR_PTR(-EINVAL);
1496}
1497EXPORT_SYMBOL(bio_map_kern); 1481EXPORT_SYMBOL(bio_map_kern);
1498 1482
1499static void bio_copy_kern_endio(struct bio *bio, int err) 1483static void bio_copy_kern_endio(struct bio *bio, int err)