forked from M-Labs/zynq-rs
eth: increase desc list safety
This commit is contained in:
parent
4e9c38527e
commit
9053166acc
|
@ -69,7 +69,8 @@ impl<'a> DescList<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
DescList {
|
DescList {
|
||||||
list,
|
// Shorten the list of descriptors to the required number.
|
||||||
|
list: &mut list[0..=last],
|
||||||
buffers,
|
buffers,
|
||||||
next: 0,
|
next: 0,
|
||||||
}
|
}
|
||||||
|
@ -85,7 +86,7 @@ impl<'a> DescList<'a> {
|
||||||
if entry.word0.read().used() {
|
if entry.word0.read().used() {
|
||||||
let word1 = entry.word1.read();
|
let word1 = entry.word1.read();
|
||||||
let len = word1.frame_length_lsbs().into();
|
let len = word1.frame_length_lsbs().into();
|
||||||
let buffer = &self.buffers[self.next][0..len];
|
let buffer = &mut self.buffers[self.next][0..len];
|
||||||
|
|
||||||
self.next += 1;
|
self.next += 1;
|
||||||
if self.next >= list_len {
|
if self.next >= list_len {
|
||||||
|
@ -107,7 +108,7 @@ impl<'a> DescList<'a> {
|
||||||
/// Releases a buffer back to the HW upon Drop
|
/// Releases a buffer back to the HW upon Drop
|
||||||
pub struct PktRef<'a> {
|
pub struct PktRef<'a> {
|
||||||
entry: &'a mut DescEntry,
|
entry: &'a mut DescEntry,
|
||||||
buffer: &'a [u8],
|
buffer: &'a mut [u8],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Drop for PktRef<'a> {
|
impl<'a> Drop for PktRef<'a> {
|
||||||
|
|
|
@ -40,6 +40,12 @@ pub struct DescList<'a> {
|
||||||
impl<'a> DescList<'a> {
|
impl<'a> DescList<'a> {
|
||||||
pub fn new(list: &'a mut [DescEntry], buffers: &'a mut [[u8; MTU]]) -> Self {
|
pub fn new(list: &'a mut [DescEntry], buffers: &'a mut [[u8; MTU]]) -> Self {
|
||||||
let last = list.len().min(buffers.len()) - 1;
|
let last = list.len().min(buffers.len()) - 1;
|
||||||
|
// Sending seems to not work properly with only one packet
|
||||||
|
// buffer (two duplicates get send with every packet), so
|
||||||
|
// check that at least 2 are allocated, i.e. that the index of
|
||||||
|
// the last one is at least one.
|
||||||
|
assert!(last > 0);
|
||||||
|
|
||||||
for (i, (entry, buffer)) in list.iter_mut().zip(buffers.iter_mut()).enumerate() {
|
for (i, (entry, buffer)) in list.iter_mut().zip(buffers.iter_mut()).enumerate() {
|
||||||
let is_last = i == last;
|
let is_last = i == last;
|
||||||
let buffer_addr = &mut buffer[0] as *mut _ as u32;
|
let buffer_addr = &mut buffer[0] as *mut _ as u32;
|
||||||
|
@ -58,7 +64,8 @@ impl<'a> DescList<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
DescList {
|
DescList {
|
||||||
list,
|
// Shorten the list of descriptors to the required number.
|
||||||
|
list: &mut list[0..=last],
|
||||||
buffers,
|
buffers,
|
||||||
next: 0,
|
next: 0,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue