tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

usb: does USBMALLOC_ZERO work correctly?



hi,

sometimes memories allocated by usb_allocmem with USBMALLOC_ZERO
are not cleared.
usb_block_allocmem, called from usb_allocmem, returns with valid dmap
if it has found a block in usb_blk_freelist. In that path memset is not done.


--- src/sys/dev/usb/usb_mem.c.orig	2021-01-05 22:12:39.913414469 +0000
+++ src/sys/dev/usb/usb_mem.c	2021-05-27 01:36:53.189148366 +0000
@@ -135,6 +135,11 @@ usb_block_allocmem(bus_dma_tag_t tag, si
 			usb_blk_nfree--;
 			*dmap = b;
 			DPRINTFN(6, "free list size=%ju", b->size, 0, 0, 0);
+			if ((flags & USBMALLOC_ZERO) != 0) {
+				memset(b->kaddr, 0, b->size);
+				bus_dmamap_sync(b->tag, b->map, 0, b->size,
+				    BUS_DMASYNC_PREWRITE);
+			}
 			return 0;
 		}
 	}


Home | Main Index | Thread Index | Old Index