Skip to contentSkip to conversation

um: vector: use kmalloc_objs() for the message vector

PATCH In review Hungyu Lin 2 participants 2 messages Oct 20 User-mode Linux (UML)

lore
Share & tools
lore

Hungyu Lin

author
#0 lore raw

PATCH 1/1 um: vector: use kmalloc_objs() for the message vector

Allocate mmsg_vector with kmalloc_objs() so the element size is derived from the destination type and the allocation helper handles multiplication overflow. The default allocation flags remain GFP_KERNEL.

---
 arch/um/drivers/vector_kern.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/um/drivers/vector_kern.c +1 -2
index e902e78c5ff6..d6127944b202 100644
@@ -528,8 +528,7 @@ static struct vector_queue *create_queue(
 		return NULL;
 	result->max_depth = max_size;
 	result->dev = vp->dev;
-	result->mmsg_vector = kmalloc(
-		(sizeof(struct mmsghdr) * max_size), GFP_KERNEL);
+	result->mmsg_vector = kmalloc_objs(*result->mmsg_vector, max_size);
 	if (result->mmsg_vector == NULL)
 		goto out_mmsg_fail;
 	result->skbuff_vector = kmalloc(

base-commit: 4ad423aa2108485f8bc5dde51fdf9c1ed979ee4b

maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 24 lines · Hungyu Lin

Allocate mmsg_vector with kmalloc_objs() so the element size is derived from the destination type and the allocation helper handles multiplication overflow. The default allocation flags remain GFP_KERNEL.

---
  arch/um/drivers/vector_kern.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
arch/um/drivers/vector_kern.c +1 -2
index e902e78c5ff6..d6127944b202 100644
@@ -528,8 +528,7 @@ static struct vector_queue *create_queue(
  		return NULL;
  	result->max_depth = max_size;
  	result->dev = vp->dev;
-	result->mmsg_vector = kmalloc(
-		(sizeof(struct mmsghdr) * max_size), GFP_KERNEL);
+	result->mmsg_vector = kmalloc_objs(*result->mmsg_vector, max_size);
  	if (result->mmsg_vector == NULL)
  		goto out_mmsg_fail;
  	result->skbuff_vector = kmalloc(
Quoted 3 lines

base-commit: 4ad423aa2108485f8bc5dde51fdf9c1ed979ee4b

Signature · 2 lines
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661