Skip to content

Commit

Permalink
screen driver: fix error in copy length reporting
Browse files Browse the repository at this point in the history
If the target kernel buffer is smaller than the userspace buffer this
commit correctly reports the amount of data _actually_ copied rather
than the amount attempted from the user.
  • Loading branch information
alevy committed Oct 25, 2024
1 parent b8caf07 commit ad60c3a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions capsules/extra/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,17 +353,19 @@ impl<'a> Screen<'a> {
.get_readonly_processbuffer(ro_allow::SHARED)
.and_then(|shared| {
shared.enter(|s| {
let mut count = 0;
let mut chunks = s.chunks(buffer_size);
if let Some(chunk) = chunks.nth(chunk_number) {
for (i, byte) in chunk.iter().enumerate() {
if pos < len {
buffer[i] = byte.get();
pos += 1
count += 1;
pos += 1;
} else {
break;
}
}
app.write_len - initial_pos
count
} else {
// stop writing
0
Expand Down

0 comments on commit ad60c3a

Please sign in to comment.