Cleanup/fix Cable connect/disconnect free/malloc issues (Hartley Sweeten)

git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1258 b68d4a1b-bc3d-0410-92ed-d4ac073336b7
master
Kolja Waschk 17 years ago
parent d68367420f
commit d6055a121b

@ -1,7 +1,10 @@
2008-05-28 Kolja Waschk <kawk>
* src/tap/cable/generic_parport.c: Fix cmd/cable.c malloc issue
(Hartley Sweeten)
* src/cmd/cable.c, src/tap/cable/wiggler.c,
src/tap/cable/generic_usbconn.c, src/tap/cable/vision_ep9307.c,
src/tap/cable/jim.c, src/tap/cable/ft2232.c,
src/tap/cable/generic_parport.c: Cable connect/disconnect cleanup,
fix malloc/free issues (Hartley Sweeten)
2008-05-27 Arnim Laeuger <arniml@users.sourceforge.net>

@ -93,8 +93,7 @@ cmd_cable_run( chain_t *chain, char *params[] )
chain_disconnect( chain );
cable = malloc( sizeof(cable_t) );
cable = calloc(1, sizeof(cable_t) );
if (!cable) {
printf( _("%s(%d) malloc failed!\n"), __FILE__, __LINE__);
return 1;
@ -104,6 +103,7 @@ cmd_cable_run( chain_t *chain, char *params[] )
if ( cable->driver->connect( ++params, cable ) ) {
printf( _("Error: Cable connection failed!\n") );
free( cable );
return 1;
}

@ -1280,9 +1280,8 @@ ft2232_connect( char *params[], cable_t *cable )
int result;
cable_params = (params_t *)malloc( sizeof(params_t) );
if (!cable_params)
{
free( cable );
if (!cable_params) {
printf( _("%s(%d) malloc failed!\n"), __FILE__, __LINE__);
return 4;
}

@ -79,8 +79,7 @@ generic_parport_connect( char *params[], cable_t *cable )
cable_params = malloc( sizeof *cable_params );
if (!cable_params) {
free( cable_params );
free( cable );
printf( _("%s(%d) malloc failed!\n"), __FILE__, __LINE__);
return 4;
}

@ -146,10 +146,8 @@ generic_usbconn_connect( char *params[], cable_t *cable )
int i;
cable_params = malloc( sizeof(generic_params_t) );
if (!cable_params)
{
free( cable );
if (!cable_params) {
printf( _("%s(%d) malloc failed!\n"), __FILE__, __LINE__);
return 4;
}

@ -47,6 +47,9 @@ jim_cable_params_t;
int
jim_cable_connect( char *params[], cable_t *cable )
{
jim_cable_params_t *cable_params;
jim_state_t *s;
if ( cmd_params( params ) < 1 ) {
printf( _("not enough arguments!\n") );
return 1;
@ -54,29 +57,21 @@ jim_cable_connect( char *params[], cable_t *cable )
printf( _("JTAG target simulator JIM - work in progress!\n"));
cable->chain = NULL;
cable->params = (jim_cable_params_t *)malloc(sizeof(jim_cable_params_t));
if(cable->params != NULL)
{
jim_state_t *s;
s = jim_init();
if(s == NULL)
{
free(cable->params);
cable->params = NULL;
}
else
{
((jim_cable_params_t *)(cable->params))->s = s;
if (!s) {
printf( _("Initialization failed.\n") );
return 3;
}
cable_params = malloc( sizeof(jim_cable_params_t) );
if (!cable_params) {
printf( _("%s(%d) malloc failed!\n"), __FILE__, __LINE__);
return 4;
}
if(cable->params == NULL)
{
printf(_("Initialization failed.\n"));
return 1;
};
cable->params = cable_params;
((jim_cable_params_t *)(cable->params))->s = s;
cable->chain = NULL;
return 0;
}

@ -164,7 +164,7 @@ ep9307_gpio_write( cable_t *cable, uint8_t data )
uint32_t tmp;
tmp = *((uint32_t*)p->gpio_PHDR);
tmp &= GPIO_BITMASK;
tmp &= ~GPIO_OUTPUT_MASK;
tmp |= data;
*((uint32_t*)p->gpio_PHDR) = tmp;
@ -201,8 +201,7 @@ ep9307_connect( char *params[], cable_t *cable )
cable_params = malloc( sizeof *cable_params );
if (!cable_params) {
printf( _("%s(%d) Out of memory\n"), __FILE__, __LINE__ );
free( cable );
printf( _("%s(%d) malloc failed!\n"), __FILE__, __LINE__);
return 4;
}
@ -213,13 +212,6 @@ ep9307_connect( char *params[], cable_t *cable )
return 0;
}
static void
ep9307_disconnect( cable_t *cable )
{
ep9307_gpio_close( cable );
chain_disconnect( cable->chain );
}
static void
ep9307_cable_free( cable_t *cable )
{
@ -236,6 +228,7 @@ ep9307_init( cable_t *cable )
return -1;
ep9307_gpio_write( cable, 1 << TRST );
cable_wait( cable );
p->trst = 1;
return 0;
@ -261,7 +254,9 @@ ep9307_clock( cable_t *cable, int tms, int tdi, int n )
for (i = 0; i < n; i++) {
ep9307_gpio_write( cable, (0 << TCK) | bit_mask );
cable_wait( cable );
ep9307_gpio_write( cable, (1 << TCK) | bit_mask );
cable_wait( cable );
}
}
@ -274,6 +269,7 @@ ep9307_get_tdo( cable_t *cable )
ep9307_params_t *p = cable->params;
ep9307_gpio_write( cable, (0 << TCK) | (p->trst << TRST) );
cable_wait( cable );
return (ep9307_gpio_read( cable ) >> TDO) & 1;
}
@ -288,6 +284,7 @@ ep9307_set_trst( cable_t *cable, int trst )
p->trst = trst ? 1 : 0;
ep9307_gpio_write( cable, p->trst << TRST );
cable_wait( cable );
return p->trst;
}
@ -310,7 +307,7 @@ cable_driver_t ep9307_cable_driver = {
"EP9307",
N_("Vision EP9307 SoM GPIO JTAG Cable"),
ep9307_connect,
ep9307_disconnect,
generic_disconnect,
ep9307_cable_free,
ep9307_init,
ep9307_done,

@ -188,8 +188,11 @@ wiggler_connect( char *params[], cable_t *cable )
if ( param_bitmap )
params[3] = param_bitmap;
if ( ( wiggler_params = malloc( sizeof *wiggler_params ) ) == NULL )
wiggler_params = malloc( sizeof *wiggler_params );
if (!wiggler_params) {
printf( _("%s(%d) malloc failed!\n"), __FILE__, __LINE__);
return 4;
}
/* set new wiggler-specific params */
free(cable->params);
@ -199,9 +202,11 @@ wiggler_connect( char *params[], cable_t *cable )
if ( ! param_bitmap )
param_bitmap = (char *)std_wgl_map;
if ( ( result = set_mapping( param_bitmap, cable ) ) != 0 )
if ( ( result = set_mapping( param_bitmap, cable ) ) != 0 ) {
printf( _("Pin mapping failed\n") );
free(cable->params);
return result;
}
/* Certain Macraigor Wigglers appear to use one of the unused data lines as a
power line so set all unused bits high. */

Loading…
Cancel
Save