[U-Boot] [u-boot] [PATCH] [2/2] [v1.3] mxc_fec: avoid free() calls to already freed pointers.

javier Martin javier.martin at vista-silicon.com
Thu Oct 22 13:59:39 CEST 2009


Sometimes, inside NetLoop, eth_halt() is called before eth_init() has
been called. This is harmless except for free() calls to pointers
which have not been allocated yet. This patch adds two states to
distinguish when it is necessary to call free() and when it is not.

This has been tested in i.MX27 Litekit board with eldk-4.2 toolchains.

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..351c75c 100644
--- a/drivers/net/fec_mxc.c
+++ b/drivers/net/fec_mxc.c
@@ -55,6 +55,7 @@ struct fec_priv gfec = {
 	.tbd_base  = NULL,
 	.tbd_index = 0,
 	.bd        = NULL,
+	.status	   = FEC_STATUS_HALT,
 };

 /*
@@ -453,6 +454,7 @@ static int fec_init(struct eth_device *dev, bd_t* bd)
 		miiphy_restart_aneg(dev);

 	fec_open(dev);
+	fec->status = FEC_STATUS_INIT;
 	return 0;
 }

@@ -491,8 +493,11 @@ static void fec_halt(struct eth_device *dev)
 	writel(0, &fec->eth->ecntrl);
 	fec->rbd_index = 0;
 	fec->tbd_index = 0;
-	free(fec->rdb_ptr);
-	free(fec->base_ptr);
+	if (fec->status == FEC_STATUS_INIT) {
+		free(fec->rdb_ptr);
+		free(fec->base_ptr);
+	}
+	fec->status = FEC_STATUS_HALT;
 	debug("eth_halt: done\n");
 }

diff --git a/drivers/net/fec_mxc.h b/drivers/net/fec_mxc.h
index 6cb1bfc..51c74ea 100644
--- a/drivers/net/fec_mxc.h
+++ b/drivers/net/fec_mxc.h
@@ -245,9 +245,19 @@ struct fec_priv {
 	bd_t *bd;
 	void *rdb_ptr;
 	void *base_ptr;
+	enum { FEC_STATUS_HALT, FEC_STATUS_INIT } status;
 };

 /**
+ * @brief Possible values for status
+ *
+ * fec_halt() changes the status to FEC_HALT_STATUS and fec_init()
+ * changes the status to FEC_INIT_STATUS
+ */
+#define FEC_STATUS_HALT 0
+#define FEC_STATUS_INIT 1
+
+/**
  * @brief Numbers of buffer descriptors for receiving
  *
  * The number defines the stocked memory buffers for the receiving task.

-- 
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