From: Tomas Hruby Date: Mon, 4 Jul 2011 08:46:51 +0000 (+0200) Subject: E1000 - fixed reading/writing device registers X-Git-Tag: v3.2.0~480 X-Git-Url: http://zhaoyanbai.com/repos/doc/roff.7.html?a=commitdiff_plain;h=d75138be002d079a28901686b9dacb6bdb9eba7d;p=minix.git E1000 - fixed reading/writing device registers - the pointers must be flagged as volatile because otherwise they might be "optimized" by a compiler. It is a common good practice to access the registers this way, the keyword is in C for a reason. - for instance, in eeprom_eerd() when polling a register the compiler, under certain conditions, may decide upon the first read and if it does not break the loop it assumes that the value is not going to change and thus stays in an infinite loop. --- diff --git a/drivers/e1000/e1000.c b/drivers/e1000/e1000.c index b4c297738..a11129d51 100644 --- a/drivers/e1000/e1000.c +++ b/drivers/e1000/e1000.c @@ -878,7 +878,7 @@ uint32_t reg; assert(reg < 0x1ffff); /* Read from memory mapped register. */ - value = *(u32_t *)(e->regs + reg); + value = *(volatile u32_t *)(e->regs + reg); /* Return the result. */ return value; @@ -896,7 +896,7 @@ uint32_t value; assert(reg < 0x1ffff); /* Write to memory mapped register. */ - *(u32_t *)(e->regs + reg) = value; + *(volatile u32_t *)(e->regs + reg) = value; } /*===========================================================================*