Skip to content

Commit 49ceb08

Browse files
committed
Cleaning up further result usage
1 parent ac594c1 commit 49ceb08

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

src/control_pipe.rs

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -186,18 +186,13 @@ impl<B: UsbBus> ControlPipe<'_, B> {
186186
Ok(None)
187187
}
188188

189-
pub fn handle_in_complete(&mut self) -> bool {
189+
pub fn handle_in_complete(&mut self) -> Result<bool> {
190190
match self.state {
191191
ControlState::DataIn => {
192-
self.write_in_chunk();
192+
self.write_in_chunk()?;
193193
}
194194
ControlState::DataInZlp => {
195-
if self.ep_in.write(&[]).is_err() {
196-
// There isn't much we can do if the write fails, except to wait for another
197-
// poll or for the host to resend the request.
198-
return false;
199-
}
200-
195+
self.ep_in.write(&[])?;
201196
usb_trace!("wrote EP0: ZLP");
202197
self.state = ControlState::DataInLast;
203198
}
@@ -207,7 +202,7 @@ impl<B: UsbBus> ControlPipe<'_, B> {
207202
}
208203
ControlState::StatusIn => {
209204
self.state = ControlState::Idle;
210-
return true;
205+
return Ok(true);
211206
}
212207
ControlState::Idle => {
213208
// If we received a message on EP0 while sending the last portion of an IN
@@ -221,23 +216,14 @@ impl<B: UsbBus> ControlPipe<'_, B> {
221216
}
222217
};
223218

224-
false
219+
Ok(false)
225220
}
226221

227-
fn write_in_chunk(&mut self) {
222+
fn write_in_chunk(&mut self) -> Result<()> {
228223
let count = min(self.len - self.i, self.ep_in.max_packet_size() as usize);
229224

230225
let buffer = self.static_in_buf.unwrap_or(&self.buf);
231-
let count = match self.ep_in.write(&buffer[self.i..(self.i + count)]) {
232-
Ok(c) => c,
233-
// There isn't much we can do if the write fails, except to wait for another poll or for
234-
// the host to resend the request.
235-
Err(_err) => {
236-
usb_debug!("Failed to write EP0: {:?}", _err);
237-
return;
238-
}
239-
};
240-
226+
let count = self.ep_in.write(&buffer[self.i..(self.i + count)])?;
241227
usb_trace!("wrote EP0: {:?}", &buffer[self.i..(self.i + count)]);
242228

243229
self.i += count;
@@ -251,6 +237,8 @@ impl<B: UsbBus> ControlPipe<'_, B> {
251237
ControlState::DataInLast
252238
};
253239
}
240+
241+
Ok(())
254242
}
255243

256244
pub fn accept_out(&mut self) -> Result<()> {
@@ -304,7 +292,7 @@ impl<B: UsbBus> ControlPipe<'_, B> {
304292
self.len = min(data_len, req.length as usize);
305293
self.i = 0;
306294
self.state = ControlState::DataIn;
307-
self.write_in_chunk();
295+
self.write_in_chunk()?;
308296

309297
Ok(())
310298
}

src/device.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,17 @@ impl<B: UsbBus> UsbDevice<'_, B> {
243243
// phases of the control transfer. If we just got a SETUP packet or
244244
// an OUT token, we can safely ignore the IN-COMPLETE indication and
245245
// continue with the next transfer.
246-
let completed = self.control.handle_in_complete();
246+
let completed = match self.control.handle_in_complete() {
247+
Ok(completed) => completed,
248+
Err(_err) => {
249+
// TODO: Propagate this out of `poll()`
250+
usb_debug!(
251+
"Failed to process control-input complete: {}",
252+
_err
253+
);
254+
false
255+
}
256+
};
247257

248258
if !B::QUIRK_SET_ADDRESS_BEFORE_STATUS
249259
&& completed

0 commit comments

Comments
 (0)