From 1ccb3b6e58a2ce778d9649df830aecdaaba212a0 Mon Sep 17 00:00:00 2001 From: Dorinda Bassey Date: Mon, 23 Oct 2023 18:44:22 +0200 Subject: [PATCH] sound/pipewire: add safety comments Signed-off-by: Dorinda Bassey --- staging/vhost-device-sound/src/audio_backends/pipewire.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/staging/vhost-device-sound/src/audio_backends/pipewire.rs b/staging/vhost-device-sound/src/audio_backends/pipewire.rs index 18e3c02..f48d0db 100644 --- a/staging/vhost-device-sound/src/audio_backends/pipewire.rs +++ b/staging/vhost-device-sound/src/audio_backends/pipewire.rs @@ -75,6 +75,8 @@ impl PwBackend { pub fn new(stream_params: Arc>>) -> Self { pw::init(); + // SAFETY: safe as the thread loop cannot access objects associated + // with the loop while the lock is held let thread_loop = unsafe { ThreadLoop::new(Some("Pipewire thread loop")).unwrap() }; let lock_guard = thread_loop.lock(); @@ -336,8 +338,10 @@ impl AudioBackend for PwBackend { } let p = &mut slice[0..n_bytes]; if avail <= 0 { - // pad with silence + // SAFETY: We have assured above that the pointer is not null + // safe to zero-initialize the pointer. unsafe { + // pad with silence ptr::write_bytes(p.as_mut_ptr(), 0, n_bytes); } } else {