Skip to content

Commit 3439032

Browse files
fix(mouse): fix panic
Before the read() function panicked when a buffer with a size > size_of<Packet>() was provided. This is now fixed and rather returns an error only when the buffer is too small. Signed-off-by: Anhad Singh <[email protected]>
1 parent 045e378 commit 3439032

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/aero_kernel/src/drivers/mouse.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,16 @@ impl Device for Mouse {
139139
impl INodeInterface for Mouse {
140140
fn read_at(&self, _offset: usize, buffer: &mut [u8]) -> fs::Result<usize> {
141141
let size = core::mem::size_of::<Packet>();
142+
143+
if buffer.len() < size {
144+
return Err(fs::FileSystemError::NotSupported);
145+
}
146+
142147
let packet = PACKETS
143148
.lock_irq()
144149
.pop()
145150
.ok_or(fs::FileSystemError::WouldBlock)?;
146151

147-
assert_eq!(buffer.len(), size);
148-
149152
unsafe {
150153
*(buffer.as_mut_ptr().cast::<Packet>()) = packet;
151154
}
@@ -161,7 +164,7 @@ impl INodeInterface for Mouse {
161164
if !PACKETS.lock_irq().is_empty() {
162165
Ok(PollFlags::IN)
163166
} else {
164-
Ok(PollFlags::OUT)
167+
Ok(PollFlags::empty())
165168
}
166169
}
167170
}

0 commit comments

Comments
 (0)