summaryrefslogtreecommitdiffstats
path: root/drivers/nor
diff options
context:
space:
mode:
authorKrzysztof Halasa <khc@pm.waw.pl>2011-01-06 16:23:01 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2011-01-07 10:21:22 +0100
commitc5baa0edc4a70c2f44cb7422e2b47ab5c96570ed (patch)
treed45c280198754e96276f6a633a206233504790b3 /drivers/nor
parentc99d28ca568a6e0d713c42bfbb9cd5310588d857 (diff)
downloadbarebox-c5baa0edc4a70c2f44cb7422e2b47ab5c96570ed.tar.gz
barebox-c5baa0edc4a70c2f44cb7422e2b47ab5c96570ed.tar.xz
Fix error handling with malloc, memalign etc. Introduce xmemalign().
The idea is to panic() when there is no memory available for normal operation. Exception: code which can consume arbitrary amount of RAM (example: files allocated in ramfs) must report error instead of panic(). This patch also fixes code which didn't check for NULL from malloc() etc. Usage: malloc(), memalign() return NULL when out of RAM. xmalloc(), xmemalign() always return non-NULL or panic(). Signed-off-by: Krzysztof HaƂasa <khc@pm.waw.pl> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/nor')
-rw-r--r--drivers/nor/cfi_flash.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/drivers/nor/cfi_flash.c b/drivers/nor/cfi_flash.c
index efe87856c4..faf965ad69 100644
--- a/drivers/nor/cfi_flash.c
+++ b/drivers/nor/cfi_flash.c
@@ -305,7 +305,7 @@ static ulong flash_get_size (struct flash_info *info, ulong base)
#endif
/* first only malloc space for the first sector */
- info->start = malloc(sizeof(ulong));
+ info->start = xmalloc(sizeof(ulong));
info->start[0] = base;
info->protect = 0;
@@ -394,8 +394,8 @@ static ulong flash_get_size (struct flash_info *info, ulong base)
cur_offset += erase_region_size * erase_region_count;
/* increase the space malloced for the sector start addresses */
- info->start = realloc(info->start, sizeof(ulong) * (erase_region_count + sect_cnt));
- info->protect = realloc(info->protect, sizeof(uchar) * (erase_region_count + sect_cnt));
+ info->start = xrealloc(info->start, sizeof(ulong) * (erase_region_count + sect_cnt));
+ info->protect = xrealloc(info->protect, sizeof(uchar) * (erase_region_count + sect_cnt));
for (j = 0; j < erase_region_count; j++) {
info->start[sect_cnt] = sector;