Skip to content

Commit ab430b9

Browse files
committed
Apply rustfmt
Set edition to 2021 Signed-off-by: Matt Johnston <[email protected]>
1 parent 5c47e9b commit ab430b9

File tree

24 files changed

+798
-536
lines changed

24 files changed

+798
-536
lines changed

.rustfmt.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
21
max_width = 80
2+
edition = "2021"

mctp-estack/src/control.rs

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77

88
//! MCTP Control Protocol implementation
99
10-
use mctp::{AsyncRespChannel, Eid, Error, Listener, MsgType};
10+
use crate::Router;
1111
use libmctp::control_packet::CompletionCode;
12+
use mctp::{AsyncRespChannel, Eid, Error, Listener, MsgType};
1213
use uuid::Uuid;
13-
use crate::Router;
1414

1515
pub use libmctp::control_packet::CommandCode;
1616

1717
type Header = libmctp::control_packet::MCTPControlMessageHeader<[u8; 2]>;
1818

1919
/// A `Result` with a MCTP Control Completion Code as error
20-
pub type ControlResult<T> = core::result::Result<T, libmctp::control_packet::CompletionCode>;
20+
pub type ControlResult<T> =
21+
core::result::Result<T, libmctp::control_packet::CompletionCode>;
2122

2223
pub struct MctpControlMsg<'a> {
2324
pub header: Header,
@@ -44,7 +45,10 @@ impl<'a> MctpControlMsg<'a> {
4445
Ok(Self { header, body })
4546
}
4647

47-
pub fn new_resp<'f>(&self, body: &'f [u8]) -> ControlResult<MctpControlMsg<'f>> {
48+
pub fn new_resp<'f>(
49+
&self,
50+
body: &'f [u8],
51+
) -> ControlResult<MctpControlMsg<'f>> {
4852
if self.header.rq() == 0 {
4953
return Err(CompletionCode::ErrorInvalidData);
5054
}
@@ -78,7 +82,12 @@ pub fn respond_get_eid<'a>(
7882
}
7983
// simple endpoint, static EID supported
8084
let endpoint_type = 0b0000_0001;
81-
let body = [CompletionCode::Success as u8, eid.0, endpoint_type, medium_specific];
85+
let body = [
86+
CompletionCode::Success as u8,
87+
eid.0,
88+
endpoint_type,
89+
medium_specific,
90+
];
8291

8392
let rsp_buf = &mut rsp_buf[0..body.len()];
8493
rsp_buf.clone_from_slice(&body);
@@ -94,15 +103,20 @@ pub struct SetEndpointId {
94103

95104
pub fn parse_set_eid(req: &MctpControlMsg) -> ControlResult<SetEndpointId> {
96105
if req.command_code() != CommandCode::SetEndpointID {
97-
return Err(CompletionCode::Error)
106+
return Err(CompletionCode::Error);
98107
}
99108
if req.body.len() != 2 {
100-
return Err(CompletionCode::ErrorInvalidLength)
109+
return Err(CompletionCode::ErrorInvalidLength);
101110
}
102111

103-
let eid = Eid::new_normal(req.body[1]).map_err(|_| CompletionCode::ErrorInvalidData)?;
112+
let eid = Eid::new_normal(req.body[1])
113+
.map_err(|_| CompletionCode::ErrorInvalidData)?;
104114

105-
let mut ret = SetEndpointId { eid, force: false, reset: false };
115+
let mut ret = SetEndpointId {
116+
eid,
117+
force: false,
118+
reset: false,
119+
};
106120

107121
match req.body[0] & 0x03 {
108122
// Set
@@ -126,13 +140,9 @@ pub fn respond_set_eid<'a>(
126140
rsp_buf: &'a mut [u8],
127141
) -> ControlResult<MctpControlMsg<'a>> {
128142
if req.command_code() != CommandCode::SetEndpointID {
129-
return Err(CompletionCode::Error)
143+
return Err(CompletionCode::Error);
130144
}
131-
let status = if accepted {
132-
0b00000000
133-
} else {
134-
0b00010000
135-
};
145+
let status = if accepted { 0b00000000 } else { 0b00010000 };
136146
let body = [CompletionCode::Success as u8, status, current_eid.0, 0x00];
137147
let rsp_buf = &mut rsp_buf[0..body.len()];
138148
rsp_buf.clone_from_slice(&body);
@@ -145,7 +155,7 @@ pub fn respond_get_uuid<'a>(
145155
rsp_buf: &'a mut [u8],
146156
) -> ControlResult<MctpControlMsg<'a>> {
147157
if req.command_code() != CommandCode::GetEndpointUUID {
148-
return Err(CompletionCode::Error)
158+
return Err(CompletionCode::Error);
149159
}
150160

151161
let mut body = [0u8; 1 + 16];
@@ -163,10 +173,10 @@ pub fn respond_get_msg_types<'a>(
163173
rsp_buf: &'a mut [u8],
164174
) -> ControlResult<MctpControlMsg<'a>> {
165175
if req.command_code() != CommandCode::GetMessageTypeSupport {
166-
return Err(CompletionCode::Error)
176+
return Err(CompletionCode::Error);
167177
}
168178
if !req.body.is_empty() {
169-
return Err(CompletionCode::ErrorInvalidLength)
179+
return Err(CompletionCode::ErrorInvalidLength);
170180
}
171181
let n = msgtypes.len();
172182
let body = rsp_buf.get_mut(..n + 2).ok_or(CompletionCode::Error)?;
@@ -194,17 +204,22 @@ pub fn respond_error<'a>(
194204
rsp_buf: &'a mut [u8],
195205
) -> mctp::Result<MctpControlMsg<'a>> {
196206
if err == CompletionCode::Success {
197-
return Err(Error::BadArgument)
207+
return Err(Error::BadArgument);
198208
}
199209
let body = [err as u8];
200210
let rsp_buf = &mut rsp_buf[0..body.len()];
201211
rsp_buf.clone_from_slice(&body);
202-
req.new_resp(rsp_buf).map_err(|_| mctp::Error::InternalError)
212+
req.new_resp(rsp_buf)
213+
.map_err(|_| mctp::Error::InternalError)
203214
}
204215

205-
pub fn mctp_control_rx_req<'f, 'l, L>(listener: &'l mut L, buf: &'f mut [u8])
206-
-> mctp::Result<(L::RespChannel<'l>, MctpControlMsg<'f>)> where L: Listener {
207-
216+
pub fn mctp_control_rx_req<'f, 'l, L>(
217+
listener: &'l mut L,
218+
buf: &'f mut [u8],
219+
) -> mctp::Result<(L::RespChannel<'l>, MctpControlMsg<'f>)>
220+
where
221+
L: Listener,
222+
{
208223
let (buf, ch, _tag, _typ, ic) = listener.recv(buf)?;
209224
if ic {
210225
return Err(Error::InvalidInput);
@@ -232,8 +247,11 @@ impl<'a> MctpControl<'a> {
232247
}
233248
}
234249

235-
pub async fn handle_async(&mut self, msg: &[u8], mut resp_chan: impl AsyncRespChannel)
236-
-> mctp::Result<()> {
250+
pub async fn handle_async(
251+
&mut self,
252+
msg: &[u8],
253+
mut resp_chan: impl AsyncRespChannel,
254+
) -> mctp::Result<()> {
237255
let req = MctpControlMsg::from_buf(msg)
238256
.map_err(|_| mctp::Error::InvalidInput)?;
239257

@@ -242,11 +260,9 @@ impl<'a> MctpControl<'a> {
242260
Ok(r) => Ok(r),
243261
}?;
244262

245-
resp_chan.send_vectored(
246-
mctp::MCTP_TYPE_CONTROL,
247-
false,
248-
&resp.slices()
249-
).await
263+
resp_chan
264+
.send_vectored(mctp::MCTP_TYPE_CONTROL, false, &resp.slices())
265+
.await
250266
}
251267

252268
pub fn set_message_types(&mut self, types: &[MsgType]) -> mctp::Result<()> {
@@ -263,7 +279,10 @@ impl<'a> MctpControl<'a> {
263279
let _ = self.uuid.insert(*uuid);
264280
}
265281

266-
async fn handle_req(&mut self, req: &'_ MctpControlMsg<'_>) -> ControlResult<MctpControlMsg> {
282+
async fn handle_req(
283+
&mut self,
284+
req: &'_ MctpControlMsg<'_>,
285+
) -> ControlResult<MctpControlMsg> {
267286
let cc = req.command_code();
268287

269288
match cc {
@@ -285,12 +304,12 @@ impl<'a> MctpControl<'a> {
285304
Err(CompletionCode::ErrorUnsupportedCmd)
286305
}
287306
}
288-
CommandCode::GetMessageTypeSupport => {
289-
respond_get_msg_types(req, self.types.as_slice(), &mut self.rsp_buf)
290-
}
291-
_ => {
292-
Err(CompletionCode::ErrorUnsupportedCmd)
293-
}
307+
CommandCode::GetMessageTypeSupport => respond_get_msg_types(
308+
req,
309+
self.types.as_slice(),
310+
&mut self.rsp_buf,
311+
),
312+
_ => Err(CompletionCode::ErrorUnsupportedCmd),
294313
}
295314
}
296315
}

mctp-estack/src/fragment.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl Fragmenter {
4646
}
4747
debug_assert!(typ.0 & 0x80 == 0, "IC bit's set in typ");
4848
debug_assert!(initial_seq & !mctp::MCTP_SEQ_MASK == 0);
49-
if mtu < HEADER_LEN+1 {
49+
if mtu < HEADER_LEN + 1 {
5050
debug!("mtu too small");
5151
return Err(Error::BadArgument);
5252
}
@@ -179,8 +179,12 @@ impl SendOutput<'_> {
179179
pub(crate) fn unborrowed<'x>(self) -> Option<SendOutput<'x>> {
180180
match self {
181181
Self::Packet(_) => unreachable!(),
182-
Self::Complete { tag, cookie } => Some(SendOutput::Complete { tag, cookie }),
183-
Self::Error { err, cookie } => Some(SendOutput::Error { err, cookie }),
182+
Self::Complete { tag, cookie } => {
183+
Some(SendOutput::Complete { tag, cookie })
184+
}
185+
Self::Error { err, cookie } => {
186+
Some(SendOutput::Error { err, cookie })
187+
}
184188
}
185189
}
186190

mctp-estack/src/i2c.rs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ impl MctpI2cEncap {
4040
self.own_addr
4141
}
4242

43-
pub fn decode<'f>(&self, mut packet: &'f [u8], pec: bool)
44-
-> Result<(&'f [u8], u8)> {
43+
pub fn decode<'f>(
44+
&self,
45+
mut packet: &'f [u8],
46+
pec: bool,
47+
) -> Result<(&'f [u8], u8)> {
4548
if pec {
4649
// Remove the pec byte, check it.
4750
if packet.is_empty() {
@@ -83,7 +86,6 @@ impl MctpI2cEncap {
8386
packet: &[u8],
8487
mctp: &'f mut Stack,
8588
) -> Result<Option<(MctpMessage<'f>, u8, ReceiveHandle)>> {
86-
8789
let (mctp_packet, i2c_src) = self.decode(packet, false)?;
8890

8991
// Pass to MCTP stack
@@ -114,9 +116,9 @@ impl MctpI2cEncap {
114116
let packet = match r {
115117
SendOutput::Packet(packet) => packet,
116118
// Just return on Complete or Error
117-
| SendOutput::Complete { .. }
118-
| SendOutput::Error { .. }
119-
=> return r.unborrowed().unwrap(),
119+
SendOutput::Complete { .. } | SendOutput::Error { .. } => {
120+
return r.unborrowed().unwrap()
121+
}
120122
};
121123

122124
// Write the i2c header and return the whole packet
@@ -135,9 +137,13 @@ impl MctpI2cEncap {
135137
SendOutput::Packet(out)
136138
}
137139

138-
pub fn encode<'f>(&self, i2c_dest: u8, inp: &[u8], out: &'f mut [u8], pec: bool)
139-
-> Result<&'f mut [u8]> {
140-
140+
pub fn encode<'f>(
141+
&self,
142+
i2c_dest: u8,
143+
inp: &[u8],
144+
out: &'f mut [u8],
145+
pec: bool,
146+
) -> Result<&'f mut [u8]> {
141147
let pec_extra = pec as usize;
142148
let out_len = MCTP_I2C_HEADER + inp.len() + pec_extra;
143149
if out.len() < out_len {
@@ -159,8 +165,8 @@ impl MctpI2cEncap {
159165
packet[..inp.len()].copy_from_slice(inp);
160166

161167
if pec {
162-
let pec_content = &out[..MCTP_I2C_HEADER+inp.len()];
163-
out[MCTP_I2C_HEADER+inp.len()] = smbus_pec::pec(pec_content);
168+
let pec_content = &out[..MCTP_I2C_HEADER + inp.len()];
169+
out[MCTP_I2C_HEADER + inp.len()] = smbus_pec::pec(pec_content);
164170
}
165171
Ok(&mut out[..out_len])
166172
}
@@ -304,8 +310,15 @@ impl MctpI2cHandler {
304310
// going through a kernel to fetch the message.
305311
fill_msg(self.send_message).ok_or(Error::InvalidInput)?;
306312

307-
let fragmenter =
308-
mctp.start_send(eid, typ, tag, true, ic, Some(MCTP_I2C_MAXMTU), cookie)?;
313+
let fragmenter = mctp.start_send(
314+
eid,
315+
typ,
316+
tag,
317+
true,
318+
ic,
319+
Some(MCTP_I2C_MAXMTU),
320+
cookie,
321+
)?;
309322
self.send_state = HandlerSendState::Sending {
310323
fragmenter,
311324
i2c_dest,

0 commit comments

Comments
 (0)