Skip to content

Commit 7c47617

Browse files
committed
node: Put NodeType <-> dev_t conversions closer together
Group all this logic together in functions inside `impl NodeType`.
1 parent 3a61424 commit 7c47617

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

src/node/mod.rs

+22-13
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,7 @@ impl DrmNode {
4444
return Err(CreateDrmNodeError::NotDrmNode);
4545
}
4646

47-
// The type of the DRM node is determined by the minor number ranges:
48-
// 0 - 63 -> Primary
49-
// 64 - 127 -> Control
50-
// 128 - 255 -> Render
51-
let ty = match minor(dev) >> 6 {
52-
0 => NodeType::Primary,
53-
1 => NodeType::Control,
54-
2 => NodeType::Render,
55-
_ => return Err(CreateDrmNodeError::NotDrmNode),
56-
};
47+
let ty = NodeType::from_dev_id(dev)?;
5748

5849
Ok(DrmNode { dev, ty })
5950
}
@@ -151,14 +142,32 @@ impl NodeType {
151142
}
152143
}
153144

145+
pub fn from_dev_id(dev: dev_t) -> Result<Self, CreateDrmNodeError> {
146+
// The type of the DRM node is determined by the minor number ranges:
147+
// 0 - 63 -> Primary
148+
// 64 - 127 -> Control
149+
// 128 - 255 -> Render
150+
Ok(match minor(dev) >> 6 {
151+
0 => Self::Primary,
152+
1 => Self::Control,
153+
2 => Self::Render,
154+
_ => return Err(CreateDrmNodeError::NotDrmNode),
155+
})
156+
}
157+
154158
#[cfg(not(target_os = "linux"))]
155-
fn minor_base(&self) -> u32 {
159+
fn minor_index(&self) -> u32 {
156160
match self {
157161
NodeType::Primary => 0,
158-
NodeType::Control => 64,
159-
NodeType::Render => 128,
162+
NodeType::Control => 1,
163+
NodeType::Render => 2,
160164
}
161165
}
166+
167+
#[cfg(not(target_os = "linux"))]
168+
fn minor_base(&self) -> u32 {
169+
self.minor_index() << 6
170+
}
162171
}
163172

164173
impl Display for NodeType {

0 commit comments

Comments
 (0)