提交 651ef90f 编写于 作者: J javier Martin 提交者: Ben Warren

mxc_fec: avoid free() calls to already freed pointers.

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 initializes those pointers to NULL and allocates them only
the first time. This way we can get rid of free calls in halt callback.

This has been tested in i.MX27 Litekit board and eldk-4.2 toolchains.
Signed-off-by: NJavier Martin <javier.martin@vista-silicon.com>
Signed-off-by: NBen Warren <biggerbadderben@gmail.com>
上级 e8f1546a
......@@ -55,6 +55,8 @@ struct fec_priv gfec = {
.tbd_base = NULL,
.tbd_index = 0,
.bd = NULL,
.rdb_ptr = NULL,
.base_ptr = NULL,
};
/*
......@@ -230,7 +232,8 @@ static int fec_rbd_init(struct fec_priv *fec, int count, int size)
uint32_t p = 0;
/* reserve data memory and consider alignment */
fec->rdb_ptr = malloc(size * count + DB_DATA_ALIGNMENT);
if (fec->rdb_ptr == NULL)
fec->rdb_ptr = malloc(size * count + DB_DATA_ALIGNMENT);
p = (uint32_t)fec->rdb_ptr;
if (!p) {
puts("fec_imx27: not enough malloc memory!\n");
......@@ -365,8 +368,9 @@ static int fec_init(struct eth_device *dev, bd_t* bd)
* Datasheet forces the startaddress of each chain is 16 byte
* aligned
*/
fec->base_ptr = malloc((2 + FEC_RBD_NUM) *
sizeof(struct fec_bd) + DB_ALIGNMENT);
if (fec->base_ptr == NULL)
fec->base_ptr = malloc((2 + FEC_RBD_NUM) *
sizeof(struct fec_bd) + DB_ALIGNMENT);
base = (uint32_t)fec->base_ptr;
if (!base) {
puts("fec_imx27: not enough malloc memory!\n");
......@@ -493,8 +497,6 @@ 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);
debug("eth_halt: done\n");
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册