Patchwork Orion NAND: Make dword load asm volatile to avoid GCC optimizing it away

login
register
mail settings
Submitter Simon Kagstrom
Date July 14, 2009, 2:41 p.m.
Message ID <20090714164135.65e91b91@marrow.netinsight.se>
Download mbox | patch
Permalink /patch/29774/
State New, archived
Headers show

Comments

Simon Kagstrom - July 14, 2009, 2:41 p.m.
GCC 4.3.3 happily removes the dword load instruction in
orion_nand_read_buf. This patch makes the inline assembly volatile to
avoid this situation.

Signed-off-by: Simon Kagstrom <simon.kagstrom@netinsight.net>
---
 drivers/mtd/nand/orion_nand.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Nicolas Pitre - July 14, 2009, 4:40 p.m.
On Tue, 14 Jul 2009, Simon Kagstrom wrote:

> GCC 4.3.3 happily removes the dword load instruction in
> orion_nand_read_buf. This patch makes the inline assembly volatile to
> avoid this situation.

If GCC does optimize away this inline asm then this is a serious GCC 
bug.  The inline asm uses an output operand for which a dependency 
exists on the very next line.

If I were you I'd try to find a non broken GCC version instead.


> Signed-off-by: Simon Kagstrom <simon.kagstrom@netinsight.net>
> ---
>  drivers/mtd/nand/orion_nand.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
> index 7ad9722..3f9b113 100644
> --- a/drivers/mtd/nand/orion_nand.c
> +++ b/drivers/mtd/nand/orion_nand.c
> @@ -61,7 +61,7 @@ static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
>  	buf64 = (uint64_t *)buf;
>  	while (i < len/8) {
>  		uint64_t x;
> -		asm ("ldrd\t%0, [%1]" : "=r" (x) : "r" (io_base));
> +		asm volatile ("ldrd\t%0, [%1]" : "=r" (x) : "r" (io_base));
>  		buf64[i++] = x;
>  	}
>  	i *= 8;
> -- 
> 1.6.0.4
> 
> 
> ______________________________________________________
> Linux MTD discussion mailing list
> http://lists.infradead.org/mailman/listinfo/linux-mtd/
>

Patch

diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
index 7ad9722..3f9b113 100644
--- a/drivers/mtd/nand/orion_nand.c
+++ b/drivers/mtd/nand/orion_nand.c
@@ -61,7 +61,7 @@  static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 	buf64 = (uint64_t *)buf;
 	while (i < len/8) {
 		uint64_t x;
-		asm ("ldrd\t%0, [%1]" : "=r" (x) : "r" (io_base));
+		asm volatile ("ldrd\t%0, [%1]" : "=r" (x) : "r" (io_base));
 		buf64[i++] = x;
 	}
 	i *= 8;