[U-Boot] [u-boot] [PATCH] [2/2] mxc_fec: put freed pointers to NULL to avoid problems with further free() calls.

javier Martin javier.martin at vista-silicon.com
Mon Oct 19 14:19:34 CEST 2009


If a free() call is used on an already freed pointer we run into
stability problems.
Put all pointers to NULL after freeing to avoid this problem.

Tested on i.MX27 Litekit board with eldk-2.0 toolchain.

Signed-off-by: Javier Martin <javier.martin at vista-silicon.com>
--

diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c
index bd83a24..7e86bc6 100644
--- a/drivers/net/fec_mxc.c
+++ b/drivers/net/fec_mxc.c
@@ -444,6 +444,7 @@ static int fec_init(struct eth_device *dev, bd_t* bd)
 	 */
 	if (fec_rbd_init(fec, FEC_RBD_NUM, FEC_MAX_PKT_SIZE) < 0) {
 		free(fec->base_ptr);
+		fec->base_ptr = NULL;
 		return -ENOMEM;
 	}
 	fec_tbd_init(fec);
@@ -492,7 +493,9 @@ static void fec_halt(struct eth_device *dev)
 	fec->rbd_index = 0;
 	fec->tbd_index = 0;
 	free(fec->rdb_ptr);
+	fec->rdb_ptr = NULL;
 	free(fec->base_ptr);
+	fec->base_ptr = NULL;
 	debug("eth_halt: done\n");
 }

-- 
Javier Martin
Vista Silicon S.L.
CDTUC - FASE C - Oficina S-345
Avda de los Castros s/n
39005- Santander. Cantabria. Spain
+34 942 25 32 60
www.vista-silicon.com


More information about the U-Boot mailing list