[PATCH rtems-lwip v1 6/9] xemacps: Avoid using memset on device memory

Kinsey Moore kinsey.moore at oarcorp.com
Fri Jul 1 22:31:09 UTC 2022


It is not safe to use memset with device memory. Device memory has
strict access alignment requirements that memset may not respect since
it can be optimized to use unaligned accesses. This avoids use of memset
with device memory.
---
 .../drivers/emacps/src/xemacps_bdring.c                  | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/embeddedsw/XilinxProcessorIPLib/drivers/emacps/src/xemacps_bdring.c b/embeddedsw/XilinxProcessorIPLib/drivers/emacps/src/xemacps_bdring.c
index 829f37c..1cbfa18 100644
--- a/embeddedsw/XilinxProcessorIPLib/drivers/emacps/src/xemacps_bdring.c
+++ b/embeddedsw/XilinxProcessorIPLib/drivers/emacps/src/xemacps_bdring.c
@@ -225,7 +225,16 @@ LONG XEmacPs_BdRingCreate(XEmacPs_BdRing * RingPtr, UINTPTR PhysAddr,
 	 *  - Clear the entire space
 	 *  - Setup each BD's BDA field with the physical address of the next BD
 	 */
+#ifndef __rtems__
 	(void)memset((void *) VirtAddrLoc, 0, (RingPtr->Separation * BdCount));
+#else
+	unsigned char* mem = (unsigned char *) VirtAddrLoc;
+	int len = RingPtr->Separation * BdCount;
+	while (len-- > 0) {
+		*mem = 0;
+		mem++;
+	}
+#endif
 
 	BdVirtAddr = VirtAddrLoc;
 	BdPhyAddr = PhysAddr + RingPtr->Separation;
-- 
2.30.2



More information about the devel mailing list