diff mbox series

[01/15] bvec: add a bvec_virt helper

Message ID 20210804095634.460779-2-hch@lst.de
State New
Headers show
Series [01/15] bvec: add a bvec_virt helper | expand

Commit Message

Christoph Hellwig Aug. 4, 2021, 9:56 a.m. UTC
Add a helper to get the virtual address for a bvec.  This avoids that
all callers need to know about the page + offset representation.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 include/linux/bvec.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Chaitanya Kulkarni Aug. 5, 2021, 6:19 a.m. UTC | #1
On 8/4/2021 2:56 AM, Christoph Hellwig wrote:
> Add a helper to get the virtual address for a bvec.  This avoids that

> all callers need to know about the page + offset representation.

> 

> Signed-off-by: Christoph Hellwig<hch@lst.de>


Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@kernel.org>


-- 
-ck
Martin K. Petersen Aug. 6, 2021, 2:38 a.m. UTC | #2
Christoph,

> Add a helper to get the virtual address for a bvec.  This avoids that

> all callers need to know about the page + offset representation.


Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>


-- 
Martin K. Petersen	Oracle Linux Engineering
diff mbox series

Patch

diff --git a/include/linux/bvec.h b/include/linux/bvec.h
index f9fa43b940ff..0e9bdd42dafb 100644
--- a/include/linux/bvec.h
+++ b/include/linux/bvec.h
@@ -229,4 +229,16 @@  static inline void memzero_bvec(struct bio_vec *bvec)
 	memzero_page(bvec->bv_page, bvec->bv_offset, bvec->bv_len);
 }
 
+/**
+ * bvec_virt - return the virtual address for a bvec
+ * @bvec: bvec to return the virtual address for
+ *
+ * Note: the caller must ensure that @bvec->bv_page is not a highmem page.
+ */
+static inline void *bvec_virt(struct bio_vec *bvec)
+{
+	WARN_ON_ONCE(PageHighMem(bvec->bv_page));
+	return page_address(bvec->bv_page) + bvec->bv_offset;
+}
+
 #endif /* __LINUX_BVEC_H */