Skip to contentSkip to conversation

media: videobuf2: Return error after allocation failure

PATCH Superseded Souptick Joarder 2 participants 3 messages Feb 3, 2019 – Feb 4, 2019

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: videobuf2: Return error after allocation failure

There is no point to continuing assignemnt after memory allocation failed, rather throw error immediately.

---
 drivers/media/common/videobuf2/videobuf2-vmalloc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/media/common/videobuf2/videobuf2-vmalloc.c +4 -4
index 6dfbd5b..d3f71e2 100644
@@ -46,16 +46,16 @@ static void *vb2_vmalloc_alloc(struct device *dev, unsigned long attrs,
 
 	buf->size = size;
 	buf->vaddr = vmalloc_user(buf->size);
-	buf->dma_dir = dma_dir;
-	buf->handler.refcount = &buf->refcount;
-	buf->handler.put = vb2_vmalloc_put;
-	buf->handler.arg = buf;
 
 	if (!buf->vaddr) {
 		pr_debug("vmalloc of size %ld failed\n", buf->size);
 		kfree(buf);
 		return ERR_PTR(-ENOMEM);
 	}
+	buf->dma_dir = dma_dir;
+	buf->handler.refcount = &buf->refcount;
+	buf->handler.put = vb2_vmalloc_put;
+	buf->handler.arg = buf;
 
 	refcount_set(&buf->refcount, 1);
 	return buf;
Signature · 1 line
1.9.1
#1 lore raw
Quoted 1 line · Souptick Joarder

There is no point to continuing assignemnt after memory allocation

assignemnt -> assignment.

Quoted 32 lines

failed, rather throw error immediately.

---
 drivers/media/common/videobuf2/videobuf2-vmalloc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/media/common/videobuf2/videobuf2-vmalloc.c +4 -4
index 6dfbd5b..d3f71e2 100644
@@ -46,16 +46,16 @@ static void *vb2_vmalloc_alloc(struct device *dev, unsigned long attrs,
 
 	buf->size = size;
 	buf->vaddr = vmalloc_user(buf->size);
-	buf->dma_dir = dma_dir;
-	buf->handler.refcount = &buf->refcount;
-	buf->handler.put = vb2_vmalloc_put;
-	buf->handler.arg = buf;
 
 	if (!buf->vaddr) {
 		pr_debug("vmalloc of size %ld failed\n", buf->size);
 		kfree(buf);
 		return ERR_PTR(-ENOMEM);
 	}
+	buf->dma_dir = dma_dir;
+	buf->handler.refcount = &buf->refcount;
+	buf->handler.put = vb2_vmalloc_put;
+	buf->handler.arg = buf;
 
 	refcount_set(&buf->refcount, 1);
 	return buf;
#2 lore raw
Quoted 5 lines · Nicolas Dufresne
Quoted 1 line · Souptick Joarder

There is no point to continuing assignemnt after memory allocation

assignemnt -> assignment.

Ah, type.

Quoted 34 lines
Quoted 33 lines

failed, rather throw error immediately.

---
 drivers/media/common/videobuf2/videobuf2-vmalloc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/media/common/videobuf2/videobuf2-vmalloc.c +4 -4
index 6dfbd5b..d3f71e2 100644
@@ -46,16 +46,16 @@ static void *vb2_vmalloc_alloc(struct device *dev, unsigned long attrs,
 
      buf->size = size;
      buf->vaddr = vmalloc_user(buf->size);
-     buf->dma_dir = dma_dir;
-     buf->handler.refcount = &buf->refcount;
-     buf->handler.put = vb2_vmalloc_put;
-     buf->handler.arg = buf;
 
      if (!buf->vaddr) {
              pr_debug("vmalloc of size %ld failed\n", buf->size);
              kfree(buf);
              return ERR_PTR(-ENOMEM);
      }
+     buf->dma_dir = dma_dir;
+     buf->handler.refcount = &buf->refcount;
+     buf->handler.put = vb2_vmalloc_put;
+     buf->handler.arg = buf;
 
      refcount_set(&buf->refcount, 1);
      return buf;