* [U-Boot] [u-boot] [PATCH] [2/2] [v1.4] mxc_fec: avoid free() calls to already freed pointers.
@ 2009-10-29 7:22 javier Martin
2009-11-10 6:53 ` Ben Warren
0 siblings, 1 reply; 2+ messages in thread
From: javier Martin @ 2009-10-29 7:22 UTC (permalink / raw)
To: u-boot
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: Javier Martin <javier.martin@vista-silicon.com>
--
drivers/net/fec_mxc.c | 12 +++++++-----
1 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c
index bd83a24..08a4dd5 100644
--- a/drivers/net/fec_mxc.c
+++ b/drivers/net/fec_mxc.c
@@ -55,6 +55,8 @@ struct fec_priv gfec = {
.tbd_base = NULL,
.tbd_index = 0,
.bd = NULL,
+ .rdb_ptr = NULL,
+ .base_ptr = NULL,
};
/*
@@ -228,7 +230,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");
@@ -363,8 +366,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");
@@ -491,8 +495,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");
}
--
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [U-Boot] [u-boot] [PATCH] [2/2] [v1.4] mxc_fec: avoid free() calls to already freed pointers.
2009-10-29 7:22 [U-Boot] [u-boot] [PATCH] [2/2] [v1.4] mxc_fec: avoid free() calls to already freed pointers javier Martin
@ 2009-11-10 6:53 ` Ben Warren
0 siblings, 0 replies; 2+ messages in thread
From: Ben Warren @ 2009-11-10 6:53 UTC (permalink / raw)
To: u-boot
javier Martin wrote:
> 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: Javier Martin <javier.martin@vista-silicon.com>
> --
> drivers/net/fec_mxc.c | 12 +++++++-----
> 1 files changed, 7 insertions(+), 5 deletions(-)
>
Applied to net repo.
thanks,
Ben
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-11-10 6:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-29 7:22 [U-Boot] [u-boot] [PATCH] [2/2] [v1.4] mxc_fec: avoid free() calls to already freed pointers javier Martin
2009-11-10 6:53 ` Ben Warren
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox