Skip to contentSkip to conversation

drivers/char/synclink.c: check kmalloc() return value.

PATCH New Amit Choudhary 1 participant 1 message Oct 25, 2006

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers/char/synclink.c: check kmalloc() return value.

Description: Check the return value of kmalloc() in function mgsl_alloc_intermediate_txbuffer_memory(), in file drivers/char/synclink.c.

drivers/char/synclink.c +6 -1
index 06784ad..24f99bc 100644
@@ -4012,8 +4012,13 @@ static int mgsl_alloc_intermediate_txbuf
 	for ( i=0; i<info->num_tx_holding_buffers; ++i) {
 		info->tx_holding_buffers[i].buffer =
 			kmalloc(info->max_frame_size, GFP_KERNEL);
-		if ( info->tx_holding_buffers[i].buffer == NULL )
+		if (info->tx_holding_buffers[i].buffer == NULL) {
+			for (--i; i >= 0; i--) {
+				kfree(info->tx_holding_buffers[i].buffer);
+				info->tx_holding_buffers[i].buffer = NULL;
+			}
 			return -ENOMEM;
+		}
 	}
 
 	return 0;