Skip to contentSkip to conversation

nand: fix buffer alignment in new verification feature

PATCH Superseded Stephen Warren 3 participants 4 messages Apr 14, 2015 – Apr 29, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 nand: fix buffer alignment in new verification feature

From: Stephen Warren <[email protected]>

On systems with caches enabled, NAND I/O may need to flush/invalidate the cache during read/write operations. For this to work correctly, all buffers must be cache-aligned. Fix nand_verify*() to allocate aligned buffers.

This prevents cache alignment warnings from being spewed when using U-Boot to write an updated version of itself to flash on NVIDIA Tegra Seaboard (after perturbation of stack/data layout in current u-boot-dm/next branch).

I have validatd (executed) nand_verify(), but I don't think I've executed nand_verify_page_oob(); testing of that would be useful.

Cc Peter Tyser <[email protected]>
Cc Heiko Schocher <[email protected]>
Cc Scott Wood <[email protected]>
Fixes 59b5a2ad83df ("nand: Add verification functions")

---
v2: Use memalign() rather than ALLOC_CACHE_ALIGN_BUFFER() so that the buffer is allocated from the heap not on the stack, to reduce stack usage.

---
 drivers/mtd/nand/nand_util.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/nand/nand_util.c +2 -2
index 12dd26a33fac..ee2c24df3b85 100644
@@ -483,7 +483,7 @@ int nand_verify_page_oob(nand_info_t *nand, struct mtd_oob_ops *ops, loff_t ofs)
 
 	memcpy(&vops, ops, sizeof(vops));
 
-	vops.datbuf = malloc(verlen);
+	vops.datbuf = memalign(ARCH_DMA_MINALIGN, verlen);
 
 	if (!vops.datbuf)
 		return -ENOMEM;
@@ -520,7 +520,7 @@ int nand_verify(nand_info_t *nand, loff_t ofs, size_t len, u_char *buf)
 	int rval = 0;
 	size_t verofs;
 	size_t verlen = nand->writesize;
-	uint8_t *verbuf = malloc(verlen);
+	uint8_t *verbuf = memalign(ARCH_DMA_MINALIGN, verlen);
 
 	if (!verbuf)
 		return -ENOMEM;
Signature · 1 line
1.9.1
#1 lore raw

PATCH v2 1/1 nand: fix buffer alignment in new verification feature

Quoted 12 lines · Stephen Warren

From: Stephen Warren <[email protected]>

On systems with caches enabled, NAND I/O may need to flush/invalidate the cache during read/write operations. For this to work correctly, all buffers must be cache-aligned. Fix nand_verify*() to allocate aligned buffers.

This prevents cache alignment warnings from being spewed when using U-Boot to write an updated version of itself to flash on NVIDIA Tegra Seaboard (after perturbation of stack/data layout in current u-boot-dm/next branch).

Quoted 8 lines

I have validatd (executed) nand_verify(), but I don't think I've executed nand_verify_page_oob(); testing of that would be useful.

Cc Peter Tyser <[email protected]>
Cc Heiko Schocher <[email protected]>
Cc Scott Wood <[email protected]>
Fixes 59b5a2ad83df ("nand: Add verification functions")
#2 lore raw

PATCH v2 1/1 nand: fix buffer alignment in new verification feature

In reply to Stephen Warren
Quoted 20 lines · Stephen Warren

From: Stephen Warren <[email protected]>

On systems with caches enabled, NAND I/O may need to flush/invalidate the cache during read/write operations. For this to work correctly, all buffers must be cache-aligned. Fix nand_verify*() to allocate aligned buffers.

This prevents cache alignment warnings from being spewed when using U-Boot to write an updated version of itself to flash on NVIDIA Tegra Seaboard (after perturbation of stack/data layout in current u-boot-dm/next branch).

I have validatd (executed) nand_verify(), but I don't think I've executed nand_verify_page_oob(); testing of that would be useful.

Cc Peter Tyser <[email protected]>
Cc Heiko Schocher <[email protected]>
Cc Scott Wood <[email protected]>
Fixes 59b5a2ad83df ("nand: Add verification functions")
Quoted 4 lines

---
v2: Use memalign() rather than ALLOC_CACHE_ALIGN_BUFFER() so that the buffer is allocated from the heap not on the stack, to reduce stack usage.

Scott, does this version look good?

#3 lore raw

PATCH v2 1/1 nand: fix buffer alignment in new verification feature

Quoted 26 lines · Stephen Warren
Quoted 20 lines · Stephen Warren

From: Stephen Warren <[email protected]>

On systems with caches enabled, NAND I/O may need to flush/invalidate the cache during read/write operations. For this to work correctly, all buffers must be cache-aligned. Fix nand_verify*() to allocate aligned buffers.

This prevents cache alignment warnings from being spewed when using U-Boot to write an updated version of itself to flash on NVIDIA Tegra Seaboard (after perturbation of stack/data layout in current u-boot-dm/next branch).

I have validatd (executed) nand_verify(), but I don't think I've executed nand_verify_page_oob(); testing of that would be useful.

Cc Peter Tyser <[email protected]>
Cc Heiko Schocher <[email protected]>
Cc Scott Wood <[email protected]>
Fixes 59b5a2ad83df ("nand: Add verification functions")
Quoted 4 lines

---
v2: Use memalign() rather than ALLOC_CACHE_ALIGN_BUFFER() so that the buffer is allocated from the heap not on the stack, to reduce stack usage.

Quoted 1 line

Scott, does this version look good?

Yes. I'll apply it the next time I look at U-Boot patches, or if you want it faster:

-Scott