[patch 02/13] mtd: SST25L (non JEDEC) SPI Flash driver
David Woodhouse
dwmw2 at infradead.org
Sat Sep 19 13:22:52 EDT 2009
On Fri, 2009-09-18 at 12:51 -0700, akpm at linux-foundation.org wrote:
>
> +static int sst25l_wait_till_ready(struct sst25l_flash *flash)
> +{
> + unsigned long deadline;
> + int status, err;
> +
> + deadline = jiffies + MAX_READY_WAIT_JIFFIES;
> + do {
> + err = sst25l_status(flash, &status);
> + if (err)
> + return err;
> + if (!(status & SST25L_STATUS_BUSY))
> + return 0;
> +
> + cond_resched();
> + } while (!time_after_eq(jiffies, deadline));
> +
> + return -ETIMEDOUT;
> +}
If your system is busy and you end up relinquishing the CPU for a long
period of time during that cond_resched(), you could hit the timeout
condition even though the hardware _is_ actually reporting 'ready'
status by the time you get back on the CPU.
It's unlikely, admittedly, but it's good practice to make sure it can't
happen like that. Something like
while (busy) {
if (timed_out) return -ETIMEDOUT;
cond_resched();
}
--
David Woodhouse Open Source Technology Centre
David.Woodhouse at intel.com Intel Corporation
More information about the linux-mtd
mailing list