Return -1 in stk500v2_open() or stk600v2_open() if drain() or getsync() fails

This commit is contained in:
Stefan Rueger
2023-07-17 19:30:59 +01:00
parent 68053b18c7
commit 9f370024c0

View File

@@ -2124,14 +2124,9 @@ static int stk500v2_open(PROGRAMMER *pgm, const char *port) {
if (serdev && serdev->usbsn)
pgm->usbsn = serdev->usbsn;
/*
* drain any extraneous input
*/
stk500v2_drain(pgm, 0);
stk500v2_getsync(pgm);
stk500v2_drain(pgm, 0);
// Drain any extraneous input, synchronise and drain again
if(stk500v2_drain(pgm, 0) < 0 || stk500v2_getsync(pgm) < 0 || stk500v2_drain(pgm, 0) < 0)
return -1;
if (pgm->bitclock != 0.0) {
if (pgm->set_sck_period(pgm, pgm->bitclock) != 0)
@@ -2181,14 +2176,9 @@ static int stk600_open(PROGRAMMER *pgm, const char *port) {
return -1;
}
/*
* drain any extraneous input
*/
stk500v2_drain(pgm, 0);
stk500v2_getsync(pgm);
stk500v2_drain(pgm, 0);
// Drain any extraneous input, synchronise and drain again
if(stk500v2_drain(pgm, 0) < 0 || stk500v2_getsync(pgm) < 0 || stk500v2_drain(pgm, 0) < 0)
return -1;
if (pgm->bitclock != 0.0) {
if (pgm->set_sck_period(pgm, pgm->bitclock) != 0)