* usbasp: replaced exit statements by return statements

* usbasp: check valid handle on usbasp_close() call


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@943 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
springob 2010-04-25 12:36:36 +00:00
parent 59010a4b6f
commit 20a65eeeb8
1 changed files with 18 additions and 17 deletions

View File

@ -140,14 +140,14 @@ static int usbasp_transmit(PROGRAMMER * pgm,
nbytes = libusb_control_transfer(PDATA(pgm)->usbhandle, nbytes = libusb_control_transfer(PDATA(pgm)->usbhandle,
(LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | (receive << 7)) & 0xff, (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | (receive << 7)) & 0xff,
functionid & 0xff, functionid & 0xff,
((send[1] << 8) | send[0]) & 0xffff, ((send[1] << 8) | send[0]) & 0xffff,
((send[3] << 8) | send[2]) & 0xffff, ((send[3] << 8) | send[2]) & 0xffff,
(char *)buffer, (char *)buffer,
buffersize & 0xffff, buffersize & 0xffff,
5000); 5000);
if(nbytes < 0){ if(nbytes < 0){
fprintf(stderr, "%s: error: usbasp_transmit: %s\n", progname, strerror(libusb_to_errno(nbytes))); fprintf(stderr, "%s: error: usbasp_transmit: %s\n", progname, strerror(libusb_to_errno(nbytes)));
exit(1); return -1;
} }
#else #else
nbytes = usb_control_msg(PDATA(pgm)->usbhandle, nbytes = usb_control_msg(PDATA(pgm)->usbhandle,
@ -159,7 +159,7 @@ static int usbasp_transmit(PROGRAMMER * pgm,
5000); 5000);
if(nbytes < 0){ if(nbytes < 0){
fprintf(stderr, "%s: error: usbasp_transmit: %s\n", progname, usb_strerror()); fprintf(stderr, "%s: error: usbasp_transmit: %s\n", progname, usb_strerror());
exit(1); return -1;
} }
#endif #endif
return nbytes; return nbytes;
@ -347,7 +347,7 @@ static int usbasp_open(PROGRAMMER * pgm, char * port)
"%s: error: could not find USB device " "%s: error: could not find USB device "
"\"NIBObee\" with vid=0x%x pid=0x%x\n", "\"NIBObee\" with vid=0x%x pid=0x%x\n",
progname, USBASP_NIBOBEE_VID, USBASP_NIBOBEE_PID); progname, USBASP_NIBOBEE_VID, USBASP_NIBOBEE_PID);
exit(1); return -1;
} }
} else if (usbOpenDevice(&PDATA(pgm)->usbhandle, USBASP_SHARED_VID, "www.fischl.de", } else if (usbOpenDevice(&PDATA(pgm)->usbhandle, USBASP_SHARED_VID, "www.fischl.de",
@ -362,7 +362,7 @@ static int usbasp_open(PROGRAMMER * pgm, char * port)
"%s: error: could not find USB device " "%s: error: could not find USB device "
"\"USBasp\" with vid=0x%x pid=0x%x\n", "\"USBasp\" with vid=0x%x pid=0x%x\n",
progname, USBASP_SHARED_VID, USBASP_SHARED_PID); progname, USBASP_SHARED_VID, USBASP_SHARED_PID);
exit(1); return -1;
} else { } else {
@ -380,15 +380,16 @@ static int usbasp_open(PROGRAMMER * pgm, char * port)
static void usbasp_close(PROGRAMMER * pgm) static void usbasp_close(PROGRAMMER * pgm)
{ {
unsigned char temp[4]; if (PDATA(pgm)->usbhandle!=NULL) {
memset(temp, 0, sizeof(temp)); unsigned char temp[4];
usbasp_transmit(pgm, 1, USBASP_FUNC_DISCONNECT, temp, temp, sizeof(temp)); memset(temp, 0, sizeof(temp));
usbasp_transmit(pgm, 1, USBASP_FUNC_DISCONNECT, temp, temp, sizeof(temp));
#ifdef USE_LIBUSB_1_0 #ifdef USE_LIBUSB_1_0
libusb_close(PDATA(pgm)->usbhandle); libusb_close(PDATA(pgm)->usbhandle);
#else #else
usb_close(PDATA(pgm)->usbhandle); usb_close(PDATA(pgm)->usbhandle);
#endif #endif
}
} }
@ -544,7 +545,7 @@ static int usbasp_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
if (n != blocksize) { if (n != blocksize) {
fprintf(stderr, "%s: error: wrong reading bytes %x\n", fprintf(stderr, "%s: error: wrong reading bytes %x\n",
progname, n); progname, n);
exit(1); return -3;
} }
buffer += blocksize; buffer += blocksize;
@ -616,7 +617,7 @@ static int usbasp_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
if (n != blocksize) { if (n != blocksize) {
fprintf(stderr, "%s: error: wrong count at writing %x\n", fprintf(stderr, "%s: error: wrong count at writing %x\n",
progname, n); progname, n);
exit(1); return -3;
} }
@ -738,11 +739,11 @@ void usbasp_initpgm(PROGRAMMER * pgm)
* optional functions * optional functions
*/ */
pgm->paged_write = usbasp_paged_write; pgm->paged_write = usbasp_paged_write;
pgm->paged_load = usbasp_paged_load; pgm->paged_load = usbasp_paged_load;
pgm->setup = usbasp_setup; pgm->setup = usbasp_setup;
pgm->teardown = usbasp_teardown; pgm->teardown = usbasp_teardown;
pgm->set_sck_period = usbasp_set_sck_period; pgm->set_sck_period = usbasp_set_sck_period;
} }
@ -754,7 +755,7 @@ static int usbasp_nousb_open (struct programmer_t *pgm, char * name)
fprintf(stderr, "%s: error: no usb support. please compile again with libusb installed.\n", fprintf(stderr, "%s: error: no usb support. please compile again with libusb installed.\n",
progname); progname);
exit(1); return -1;
} }
void usbasp_initpgm(PROGRAMMER * pgm) void usbasp_initpgm(PROGRAMMER * pgm)