Skip to content

Commit 464c6ff

Browse files
committed
treewide: use read_to_string directly
Signed-off-by: Stefan Kerkmann <s.kerkmann@pengutronix.de>
1 parent d5cad5e commit 464c6ff

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/cmdline.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22

3+
use std::fs::read_to_string;
4+
35
use nix::mount::MsFlags;
46

5-
use crate::{read_file, Result};
7+
use crate::Result;
68

79
pub struct CmdlineOptions {
810
pub root: Option<String>,
@@ -67,7 +69,7 @@ fn parse_nfsroot(options: &mut CmdlineOptions) -> Result<()> {
6769
};
6870
rootflags.push_str(",addr=");
6971
if !nfsroot.contains(':') {
70-
let pnp = read_file("/proc/net/pnp")?;
72+
let pnp = read_to_string("/proc/net/pnp")?;
7173
for line in pnp.lines() {
7274
match line.split_once(' ') {
7375
None => continue,

src/dmverity.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22

33
use std::fs::OpenOptions;
4+
use std::fs::{read_to_string, OpenOptions};
45
use std::mem::size_of;
56
use std::os::fd::IntoRawFd;
67
use std::path::Path;
@@ -12,7 +13,7 @@ use nix::libc::dev_t;
1213
use nix::sys::stat::minor;
1314

1415
use crate::cmdline::CmdlineOptions;
15-
use crate::{read_file, Result};
16+
use crate::Result;
1617

1718
const DM_VERSION_MAJOR: u32 = 4;
1819

@@ -132,7 +133,7 @@ pub fn prepare_dmverity(options: &mut CmdlineOptions) -> Result<bool> {
132133
let mut salt = "";
133134
let mut root_hash = "";
134135

135-
let params = read_file("/verity-params")?;
136+
let params = read_to_string("/verity-params")?;
136137
for line in params.lines() {
137138
match line.split_once('=') {
138139
None => continue,

src/main.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ pub fn mkdir(dir: &str) -> Result<()> {
4646
Ok(())
4747
}
4848

49-
fn read_file(filename: &str) -> std::result::Result<String, String> {
50-
read_to_string(filename).map_err(|e| format!("Failed to read {filename}: {e}"))
51-
}
52-
5349
/*
5450
* Setup stdout/stderr. The kernel will create /dev/console in the
5551
* initramfs, so we can use that.
@@ -152,7 +148,7 @@ fn init() -> Result<()> {
152148

153149
setup_log()?;
154150

155-
let cmdline = read_file("/proc/cmdline")?;
151+
let cmdline = read_to_string("/proc/cmdline")?;
156152
let mut options = CmdlineOptions {
157153
..Default::default()
158154
};

0 commit comments

Comments
 (0)