From 540b4be57d77b6a3e8a0063a641097258c6ec2e4 Mon Sep 17 00:00:00 2001 From: Kolja Waschk Date: Sun, 16 Dec 2007 11:03:17 +0000 Subject: [PATCH] Fix [ 1851777 ] segfault when running "detectflash" git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@855 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- jtag/ChangeLog | 2 ++ jtag/libbrux/flash/amd_flash.c | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/jtag/ChangeLog b/jtag/ChangeLog index 4231aba3..acfac264 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -1,5 +1,7 @@ 2007-12-16 Kolja Waschk + * libbrux/amd/amd_flash.c: Fix for [1851777] segfault when + running detectflash * include/setdevice.h, include/Makefile.am, src/detect.c, src/cmd/setdevice.c, src/cmd/cmd.c, src/cmd/Makefile.am, src/jtag.c, doc/UrJTAG.txt, libbrux/flash/amd_flash.c, diff --git a/jtag/libbrux/flash/amd_flash.c b/jtag/libbrux/flash/amd_flash.c index 2062d0e2..376ea741 100644 --- a/jtag/libbrux/flash/amd_flash.c +++ b/jtag/libbrux/flash/amd_flash.c @@ -90,6 +90,13 @@ int amd_detect(bus_t *bus, uint32_t adr, cfi_array_t **cfi_array ) bus_area_t area; cfi_query_structure_t *cfi ; + if (!cfi_array || !bus) + return -1; /* invalid parameters */ + + *cfi_array = calloc( 1, sizeof (cfi_array_t) ); + if (!*cfi_array) + return -2; /* out of memory */ + bus_write( bus, adr+0x0, 0xf0 ); bus_write( bus, adr+0x555, 0xaa ); bus_write( bus, adr+0x2AA, 0x55 ); @@ -115,10 +122,6 @@ int amd_detect(bus_t *bus, uint32_t adr, cfi_array_t **cfi_array ) break; } - *cfi_array = calloc( 1, sizeof (cfi_array_t) ); - if (!*cfi_array) - return -2; /* out of memory */ - (*cfi_array)->bus = bus; (*cfi_array)->address = 0; if (bus_area( bus, adr+0, &area ) != 0)