lkml.org 
[lkml]   [2022]   [Mar]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] staging: mmal-vchiq: add a check for the return of vmalloc()
Date
From: Xiaoke Wang <xkernel.wang@foxmail.com>

vmalloc() is a memory allocation API which can return NULL when some
internal memory errors happen. So it is better to check the return
value of it to catch the error in time.

Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
index 76d3f03..1bbd301 100644
--- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
+++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
@@ -1909,6 +1909,11 @@ int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
mutex_init(&instance->vchiq_mutex);

instance->bulk_scratch = vmalloc(PAGE_SIZE);
+ if (!instance->bulk_scratch) {
+ err = -ENOMEM;
+ kfree(instance);
+ goto err_shutdown_vchiq;
+ }
instance->vchiq_instance = vchiq_instance;

mutex_init(&instance->context_map_lock);
--
\
 
 \ /
  Last update: 2022-03-04 09:18    [W:0.174 / U:0.084 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site