[09/11] xf86drmSL: Check memory allocation by SL_RANDOM_INIT()

Submitted by Praveen Paneri on April 10, 2015, 8:43 a.m.

Details

Message ID 1428655383-26087-10-git-send-email-praveen.paneri@intel.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Praveen Paneri April 10, 2015, 8:43 a.m.
If the allocation fails, return -ENOMEM. Handle the return value
at the caller funtion drmSLInsert() as well.

v2: Rebased to the latest.

Signed-off-by: Praveen Paneri <praveen.paneri@intel.com>
---
 xf86drmSL.c | 5 +++++
 1 file changed, 5 insertions(+)

Patch hide | download patch | download mbox

diff --git a/xf86drmSL.c b/xf86drmSL.c
index 42b5bc4..3ceb087 100644
--- a/xf86drmSL.c
+++ b/xf86drmSL.c
@@ -40,6 +40,7 @@ 
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <errno.h>
 
 #include "xf86drm.h"
 
@@ -92,6 +93,7 @@  static int SLRandomLevel(void)
     SL_RANDOM_DECL;
 
     SL_RANDOM_INIT(SL_RANDOM_SEED);
+    if (!state) return -ENOMEM;
     
     while ((SL_RANDOM & 0x01) && level < SL_MAX_LEVEL) ++level;
     return level;
@@ -168,6 +170,9 @@  int drmSLInsert(void *l, unsigned long key, void *value)
 
 
     level = SLRandomLevel();
+    if (level < 0)
+	return level;
+
     if (level > list->level) {
 	level = ++list->level;
 	update[level] = list->head;