[ewg] [PATCH] IB/core: return immediate error when registering zero length buffer

Eli Cohen eli at mellanox.co.il
Sun Jul 27 05:13:59 PDT 2008


Registering a zero length buffer is meaningless so check this at
ib_umem_get() and return immediately with error if that is the case.
If we don't do this, we get an inconsistent behaviour. For example,
if we register a buffer whose start address is not page aligned, we
will end up registering one page, while if the address is page
aligned, we will have zero pages -- the reason for this comes from
the following statement:

npages = PAGE_ALIGN(size + umem->offset) >> PAGE_SHIFT;

Problem found by: Ronni Zimmermann <ronniz at mellanox.co.il>
Signed-off-by: Eli Cohen <eli at mellanox.co.il>
---
 drivers/infiniband/core/umem.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c
index 6f7c096..2541ef8 100644
--- a/drivers/infiniband/core/umem.c
+++ b/drivers/infiniband/core/umem.c
@@ -89,6 +89,9 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
 	int i;
 	DEFINE_DMA_ATTRS(attrs);
 
+	if (!size)
+		return ERR_PTR(-ENOMEM);
+
 	if (dmasync)
 		dma_set_attr(DMA_ATTR_WRITE_BARRIER, &attrs);
 
-- 
1.5.6




More information about the ewg mailing list