Skip to content

Commit 94ea2aa

Browse files
committed
types: Use Box in place of a lifetimed reference for QdlReadWrite
Due to how the protocol is constructed, we don't have to worry about multiple things poking at the r/w channel at once - emphasize that and store it inside the QdlDevice. Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
1 parent cd87f7b commit 94ea2aa

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

cli/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,12 @@ fn main() -> Result<()> {
209209
);
210210

211211
// Set up the device
212-
let mut rw_channel = match setup_target_device(backend, args.serial_no, args.dev_path) {
212+
let rw_channel = match setup_target_device(backend, args.serial_no, args.dev_path) {
213213
Ok(c) => c,
214214
Err(e) => bail!("Couldn't set up device: {}", e.to_string()),
215215
};
216216
let mut qdl_dev = QdlDevice {
217-
rw: rw_channel.as_mut(),
217+
rw: rw_channel,
218218
fh_cfg: FirehoseConfiguration {
219219
hash_packets: args.hash_packets,
220220
read_back_verify: args.read_back_verify,

qdl/src/types.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,30 @@ pub trait QdlChan: Read + Write {
9494
}
9595

9696
pub trait QdlReadWrite: Read + Write + Send + Sync {}
97-
impl<T> QdlReadWrite for &mut T where T: QdlReadWrite {}
97+
impl<T> QdlReadWrite for &mut T where T: QdlReadWrite + ?Sized {}
9898

99-
pub struct QdlDevice<'a> {
100-
pub rw: &'a mut dyn QdlReadWrite,
99+
pub struct QdlDevice<T>
100+
where
101+
T: QdlReadWrite + ?Sized,
102+
{
103+
pub rw: Box<T>,
101104
pub fh_cfg: FirehoseConfiguration,
102105
pub reset_on_drop: bool,
103106
}
104107

105-
impl Read for QdlDevice<'_> {
108+
impl<T> Read for QdlDevice<T>
109+
where
110+
T: QdlReadWrite + ?Sized,
111+
{
106112
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
107113
self.rw.read(buf)
108114
}
109115
}
110116

111-
impl Write for QdlDevice<'_> {
117+
impl<T> Write for QdlDevice<T>
118+
where
119+
T: QdlReadWrite + ?Sized,
120+
{
112121
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
113122
self.rw.write(buf)
114123
}
@@ -118,7 +127,10 @@ impl Write for QdlDevice<'_> {
118127
}
119128
}
120129

121-
impl QdlChan for QdlDevice<'_> {
130+
impl<T> QdlChan for QdlDevice<T>
131+
where
132+
T: QdlReadWrite + ?Sized,
133+
{
122134
fn fh_config(&self) -> &FirehoseConfiguration {
123135
&self.fh_cfg
124136
}
@@ -128,7 +140,10 @@ impl QdlChan for QdlDevice<'_> {
128140
}
129141
}
130142

131-
impl Drop for QdlDevice<'_> {
143+
impl<T> Drop for QdlDevice<T>
144+
where
145+
T: QdlReadWrite + ?Sized,
146+
{
132147
fn drop(&mut self) {
133148
// Avoid having the board be stuck in EDL limbo in case of errors
134149
// TODO: watch 'rawmode' and adjust accordingly

qramdump/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ pub fn main() -> Result<()> {
3939
None => QdlBackend::default(),
4040
};
4141

42-
let mut rw_channel = match setup_target_device(backend, args.serial_no, args.dev_path) {
42+
let rw_channel = match setup_target_device(backend, args.serial_no, args.dev_path) {
4343
Ok(c) => c,
4444
Err(e) => bail!("Couldn't set up device: {}", e.to_string()),
4545
};
4646

4747
let mut qdl_dev = QdlDevice {
48-
rw: rw_channel.as_mut(),
48+
rw: rw_channel,
4949
fh_cfg: FirehoseConfiguration::default(),
5050
reset_on_drop: false,
5151
};

0 commit comments

Comments
 (0)