while(eeprom.busy) { interruptible_sleep_on(&eeprom.wait_q); /* bail out if we get interrupted */ if (signal_pending(current)) return -EINTR; } 
wait_event_interruptible(eeprom.wait_q, !eeprom.busy); /* bail out if we get interrupted */ if (signal_pending(current)) return -EINTR; 
static ssize_t eeprom_write(struct file * file, const char * buf, size_t count,                            loff_t *off){  int i, written, restart=1;  unsigned long p;  if (!access_ok(VERIFY_READ, buf, count))  {    return -EFAULT;  }  while(eeprom.busy)  {    interruptible_sleep_on(&eeprom.wait_q);    /* bail out if we get interrupted */    if (signal_pending(current))      return -EINTR;  }  eeprom.busy++;  for(i = 0; (i < EEPROM_RETRIES) && (restart > 0); i++)  {    restart = 0;    written = 0;    p = file->f_pos;           while( (written < count) && (p < eeprom.size))    {      /* address the eeprom */      if(!eeprom_address(p))      {        printk(KERN_INFO "%s: Write failed to address the eeprom: "               "0x%08X (%i) \n", eeprom_name, (int)p, (int)p);        i2c_stop();                /* don't forget to wake them up */        eeprom.busy--;        wake_up_interruptible(&eeprom.wait_q);        return -EFAULT;      }#ifdef EEPROM_ADAPTIVE_TIMING            /* Adaptive algorithm to adjust timing */      if (eeprom.retry_cnt_addr > 0)      {        /* To Low now */        D(printk(">D=%i d=%i\n",               eeprom.usec_delay_writecycles, eeprom.usec_delay_step));        if (eeprom.usec_delay_step < 4)        {          eeprom.usec_delay_step++;          eeprom.usec_delay_writecycles += eeprom.usec_delay_step;        }        else        {          if (eeprom.adapt_state > 0)          {            /* To Low before */            eeprom.usec_delay_step *= 2;            if (eeprom.usec_delay_step > 2)            {              eeprom.usec_delay_step--;            }            eeprom.usec_delay_writecycles += eeprom.usec_delay_step;          }          else if (eeprom.adapt_state < 0)          {            /* To High before (toggle dir) */            eeprom.usec_delay_writecycles += eeprom.usec_delay_step;            if (eeprom.usec_delay_step > 1)            {              eeprom.usec_delay_step /= 2;              eeprom.usec_delay_step--;            }          }        }        eeprom.adapt_state = 1;      }      else      {        /* To High (or good) now */        D(printk("<D=%i d=%i\n",               eeprom.usec_delay_writecycles, eeprom.usec_delay_step));                if (eeprom.adapt_state < 0)        {          /* To High before */          if (eeprom.usec_delay_step > 1)          {            eeprom.usec_delay_step *= 2;            eeprom.usec_delay_step--;                        if (eeprom.usec_delay_writecycles > eeprom.usec_delay_step)            {              eeprom.usec_delay_writecycles -= eeprom.usec_delay_step;            }          }        }        else if (eeprom.adapt_state > 0)        {          /* To Low before (toggle dir) */          if (eeprom.usec_delay_writecycles > eeprom.usec_delay_step)          {            eeprom.usec_delay_writecycles -= eeprom.usec_delay_step;          }          if (eeprom.usec_delay_step > 1)          {            eeprom.usec_delay_step /= 2;            eeprom.usec_delay_step--;          }                    eeprom.adapt_state = -1;        }        if (eeprom.adapt_state > -100)        {          eeprom.adapt_state--;        }        else        {          /* Restart adaption */          D(printk("#Restart\n"));          eeprom.usec_delay_step++;        }      }#endif /* EEPROM_ADAPTIVE_TIMING */      /* write until we hit a page boundary or count */      do      {        i2c_outbyte(buf[written]);                if(!i2c_getack())        {          restart=1;          printk(KERN_INFO "%s: write error, retrying. %d\n", eeprom_name, i);          i2c_stop();          break;        }        written++;        p++;              } while( written < count && ( p % eeprom.sequential_write_pagesize ));      /* end write cycle */      i2c_stop();      i2c_delay(eeprom.usec_delay_writecycles);    } /* while */  } /* for  */  eeprom.busy--;  wake_up_interruptible(&eeprom.wait_q);  if (written == 0 && file->f_pos >= eeprom.size){    return -ENOSPC;  }  file->f_pos += written;  return written;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/7e9204265b4ec6680fad9abc7a78b94087983916/eeprom.c/buggy/arch/cris/arch-v10/drivers/eeprom.c