rem: return -1;
add: LED_OFF(fd, pgm->pinno[PIN_LED_PGM]); LED_ON(fd, pgm->pinno[PIN_LED_ERR]); return -4;
context: int avr_write_byte(int fd, AVRPART * p, AVRMEM * mem,                   unsigned long addr, unsigned char data){  unsigned char cmd[4];  unsigned char res[4];  unsigned char r;  int ready;  int tries;  unsigned char b;  unsigned short caddr;  OPCODE * writeop;  int rc;  int readok=0;  if (!mem->paged) {    /*      * check to see if the write is necessary by reading the existing     * value and only write if we are changing the value; we can't     * use this optimization for paged addressing.     */    rc = avr_read_byte(fd, p, mem, addr, &b);    if (rc != 0) {      if (rc != -1) {        return -1;      }      /*       * the read operation is not support on this memory type       */    }    else {      readok = 1;      if (b == data) {        return 0;      }    }  }  /*   * determine which memory opcode to use   */  if (mem->op[AVR_OP_WRITE_LO]) {    if (addr & 0x01)      writeop = mem->op[AVR_OP_WRITE_HI];    else      writeop = mem->op[AVR_OP_WRITE_LO];    caddr = addr / 2;  }  else if (mem->op[AVR_OP_LOADPAGE_LO]) {    if (addr & 0x01)      writeop = mem->op[AVR_OP_LOADPAGE_HI];    else      writeop = mem->op[AVR_OP_LOADPAGE_LO];    caddr = addr / 2;  }  else {    writeop = mem->op[AVR_OP_WRITE];    caddr = addr;  }  if (writeop == NULL) {#if DEBUG    fprintf(stderr,             "avr_write_byte(): write not supported for memory type \"%s\"\n",            mem->desc);#endif    return -1;  }  LED_ON(fd, pgm->pinno[PIN_LED_PGM]);  LED_OFF(fd, pgm->pinno[PIN_LED_ERR]);  memset(cmd, 0, sizeof(cmd));  avr_set_bits(writeop, cmd);  avr_set_addr(writeop, cmd, caddr);  avr_set_input(writeop, cmd, data);  avr_cmd(fd, cmd, res);  if (mem->paged) {    /*     * in paged addressing, single bytes to written to the memory     * page complete immediately, we only need to delay when we commit     * the whole page via the avr_write_page() routine.     */    LED_OFF(fd, pgm->pinno[PIN_LED_PGM]);    return 0;  }  if (readok == 0) {    /*     * read operation not supported for this memory type, just wait     * the max programming time and then return      */    usleep(mem->max_write_delay); /* maximum write delay */    LED_OFF(fd, pgm->pinno[PIN_LED_PGM]);    return 0;  }  tries = 0;  ready = 0;  while (!ready) {    usleep(mem->min_write_delay); /* typical write delay */    rc = avr_read_byte(fd, p, mem, addr, &r);    if (rc != 0) {      return -1;    }    if ((data == mem->readback[0]) ||        (data == mem->readback[1])) {      /*        * use an extra long delay when we happen to be writing values       * used for polled data read-back.  In this case, polling       * doesn't work, and we need to delay the worst case write time       * specified for the chip.       */      usleep(mem->max_write_delay);      rc = avr_read_byte(fd, p, mem, addr, &r);      if (rc != 0) {        return -1;      }    }        if (r == data) {      ready = 1;    }        tries++;    if (!ready && tries > 5) {      /*       * we couldn't write the data, indicate our displeasure by       * returning an error code        */      LED_OFF(fd, pgm->pinno[PIN_LED_PGM]);      LED_ON(fd, pgm->pinno[PIN_LED_ERR]);            return -1;    }  }  LED_OFF(fd, pgm->pinno[PIN_LED_PGM]);  return 0;}