Skip to contentSkip to conversation

sound/oss/i810_audio.c: check kmalloc() return value.

PATCH In review Amit Choudhary 2 participants 2 messages Oct 23, 2006 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sound/oss/i810_audio.c: check kmalloc() return value.

Description: Check the return value of kmalloc() in function i810_open(), in file sound/oss/i810_audio.c.

sound/oss/i810_audio.c +6 -1
index 240cc79..a415967 100644
@@ -2580,8 +2580,13 @@ static int i810_open(struct inode *inode
 			if (card->states[i] == NULL) {
 				state = card->states[i] = (struct i810_state *)
 					kmalloc(sizeof(struct i810_state), GFP_KERNEL);
-				if (state == NULL)
+				if (state == NULL) {
+					for (--i; i >= 0; i--) {
+						kfree(card->states[i]);
+						card->states[i] = NULL;
+					}
 					return -ENOMEM;
+				}
 				memset(state, 0, sizeof(struct i810_state));
 				dmabuf = &state->dmabuf;
 				goto found_virt;
#1 lore raw
Quoted 5 lines · Amit Choudhary
sound/oss/i810_audio.c +0 -1
@@ -2580,8 +2580,13 @@ static int i810_open(struct inode *inode
                        if (card->states[i] == NULL) {
                                state = card->states[i] = (struct i810_state *)
                                        kmalloc(sizeof(struct i810_state), GFP_KERNEL);
-                               if (state == NULL)

sound/oss/i810_audio.c static int i810_open(struct inode *inode · line 2592

Quoted 10 lines
sound/oss/i810_audio.c +6 -0
+                               if (state == NULL) {
+                                       for (--i; i >= 0; i--) {
+                                               kfree(card->states[i]);
+                                               card->states[i] = NULL;
+                                       }
                                        return -ENOMEM;
+                               }
                                memset(state, 0, sizeof(struct i810_state));
                                dmabuf = &state->dmabuf;
                                goto found_virt;

Looks wrong to me. We only allocate memory once in the loop (hint:
goto found_virt at the bottom here).