mirror of
https://github.com/torvalds/linux.git
synced 2025-08-15 14:11:42 +02:00
block: simplify bio_map_kern
Rewrite bio_map_kern using the new bio_add_* helpers and drop the kerneldoc comment that is superfluous for an internal helper. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Link: https://lore.kernel.org/r/20250507120451.4000627-8-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
fddbc51dc2
commit
6ff54f4566
1 changed files with 9 additions and 47 deletions
|
@ -317,64 +317,26 @@ static void bio_map_kern_endio(struct bio *bio)
|
||||||
kfree(bio);
|
kfree(bio);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static struct bio *bio_map_kern(void *data, unsigned int len, enum req_op op,
|
||||||
* bio_map_kern - map kernel address into bio
|
gfp_t gfp_mask)
|
||||||
* @data: pointer to buffer to map
|
|
||||||
* @len: length in bytes
|
|
||||||
* @op: bio/request operation
|
|
||||||
* @gfp_mask: allocation flags for bio allocation
|
|
||||||
*
|
|
||||||
* Map the kernel address into a bio suitable for io to a block
|
|
||||||
* device. Returns an error pointer in case of error.
|
|
||||||
*/
|
|
||||||
static struct bio *bio_map_kern(void *data, unsigned int len,
|
|
||||||
enum req_op op, gfp_t gfp_mask)
|
|
||||||
{
|
{
|
||||||
unsigned long kaddr = (unsigned long)data;
|
unsigned int nr_vecs = bio_add_max_vecs(data, len);
|
||||||
unsigned long end = (kaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
|
||||||
unsigned long start = kaddr >> PAGE_SHIFT;
|
|
||||||
const int nr_pages = end - start;
|
|
||||||
bool is_vmalloc = is_vmalloc_addr(data);
|
|
||||||
struct page *page;
|
|
||||||
int offset, i;
|
|
||||||
struct bio *bio;
|
struct bio *bio;
|
||||||
|
|
||||||
bio = bio_kmalloc(nr_pages, gfp_mask);
|
bio = bio_kmalloc(nr_vecs, gfp_mask);
|
||||||
if (!bio)
|
if (!bio)
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
bio_init(bio, NULL, bio->bi_inline_vecs, nr_pages, op);
|
bio_init(bio, NULL, bio->bi_inline_vecs, nr_vecs, op);
|
||||||
|
if (is_vmalloc_addr(data)) {
|
||||||
if (is_vmalloc) {
|
|
||||||
flush_kernel_vmap_range(data, len);
|
|
||||||
bio->bi_private = data;
|
bio->bi_private = data;
|
||||||
}
|
if (!bio_add_vmalloc(bio, data, len)) {
|
||||||
|
|
||||||
offset = offset_in_page(kaddr);
|
|
||||||
for (i = 0; i < nr_pages; i++) {
|
|
||||||
unsigned int bytes = PAGE_SIZE - offset;
|
|
||||||
|
|
||||||
if (len <= 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (bytes > len)
|
|
||||||
bytes = len;
|
|
||||||
|
|
||||||
if (!is_vmalloc)
|
|
||||||
page = virt_to_page(data);
|
|
||||||
else
|
|
||||||
page = vmalloc_to_page(data);
|
|
||||||
if (bio_add_page(bio, page, bytes, offset) < bytes) {
|
|
||||||
/* we don't support partial mappings */
|
|
||||||
bio_uninit(bio);
|
bio_uninit(bio);
|
||||||
kfree(bio);
|
kfree(bio);
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
data += bytes;
|
bio_add_virt_nofail(bio, data, len);
|
||||||
len -= bytes;
|
|
||||||
offset = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bio->bi_end_io = bio_map_kern_endio;
|
bio->bi_end_io = bio_map_kern_endio;
|
||||||
return bio;
|
return bio;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue