Skip to content

Commit 750c458

Browse files
Fredrik Simonssonepilys
authored andcommitted
Remove unwraps in scmi
A few unwraps which may or may not be needed was replaced with Result types. Signed-off-by: Fredrik Simonsson <[email protected]>
1 parent 68c2a0f commit 750c458

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

vhost-device-scmi/src/main.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ impl TryFrom<args::ScmiArgs> for VuScmiConfig {
6969
let device_iterator = cmd_args.device.iter();
7070
for d in device_iterator {
7171
let mut split = d.split(',');
72-
let name = split.next().unwrap().to_owned();
72+
let name = split
73+
.next()
74+
.ok_or("String split failed with None")?
75+
.to_owned();
7376
let mut properties = vec![];
7477
for s in split {
7578
if let Some((key, value)) = s.split('=').collect_tuple() {
@@ -95,18 +98,21 @@ fn start_backend(config: VuScmiConfig) -> Result<()> {
9598
return Err(error.to_string());
9699
}
97100

98-
let backend = Arc::new(RwLock::new(backend_instance.unwrap()));
101+
let backend = Arc::new(RwLock::new(backend_instance.map_err(|e| format!("{e}"))?));
99102
let mut daemon = VhostUserDaemon::new(
100103
"vhost-device-scmi".to_owned(),
101104
backend.clone(),
102105
GuestMemoryAtomic::new(GuestMemoryMmap::new()),
103106
)
104-
.unwrap();
107+
.map_err(|e| format!("{e}"))?;
105108

106109
// Register devices such as "/dev/iio:deviceX" which can actively notify the frontend to epoll the handler.
107110
// Then once there is data coming from these devices, an event will be created. (device_event=3)
108111
let handlers = daemon.get_epoll_handlers();
109-
backend.read().unwrap().register_device_event_fd(handlers);
112+
backend
113+
.read()
114+
.map_err(|e| format!("{e}"))?
115+
.register_device_event_fd(handlers);
110116

111117
daemon
112118
.serve(&config.socket_path)

vhost-device-scmi/src/vhu_scmi.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,13 @@ impl VhostUserBackendMut for VuScmiBackend {
512512
_ => {
513513
if device_event >= NOTIFY_ALLOW_START_FD && device_event <= max_device_event {
514514
let vring = &vrings[EVENT_QUEUE as usize];
515-
vring.disable_notification().unwrap();
515+
vring
516+
.disable_notification()
517+
.map_err(|error: virtio_queue::Error| std::io::Error::other(error))?;
516518
self.notify_event_queue(vring, device_event)?;
517-
vring.enable_notification().unwrap();
519+
vring
520+
.enable_notification()
521+
.map_err(|error: virtio_queue::Error| std::io::Error::other(error))?;
518522
} else {
519523
warn!("unhandled device_event: {}", device_event);
520524
return Err(VuScmiError::HandleEventUnknownEvent.into());

0 commit comments

Comments
 (0)