Skip to content

Commit

Permalink
node: Put NodeType <-> dev_t conversions closer together
Browse files Browse the repository at this point in the history
Group all this logic together in functions inside `impl NodeType`.
  • Loading branch information
MarijnS95 committed Nov 1, 2024
1 parent 3a61424 commit 7c47617
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,7 @@ impl DrmNode {
return Err(CreateDrmNodeError::NotDrmNode);
}

// The type of the DRM node is determined by the minor number ranges:
// 0 - 63 -> Primary
// 64 - 127 -> Control
// 128 - 255 -> Render
let ty = match minor(dev) >> 6 {
0 => NodeType::Primary,
1 => NodeType::Control,
2 => NodeType::Render,
_ => return Err(CreateDrmNodeError::NotDrmNode),
};
let ty = NodeType::from_dev_id(dev)?;

Ok(DrmNode { dev, ty })
}
Expand Down Expand Up @@ -151,14 +142,32 @@ impl NodeType {
}
}

pub fn from_dev_id(dev: dev_t) -> Result<Self, CreateDrmNodeError> {

Check warning on line 145 in src/node/mod.rs

View workflow job for this annotation

GitHub Actions / check-minimal

missing documentation for an associated function

Check warning on line 145 in src/node/mod.rs

View workflow job for this annotation

GitHub Actions / doc

missing documentation for an associated function
// The type of the DRM node is determined by the minor number ranges:
// 0 - 63 -> Primary
// 64 - 127 -> Control
// 128 - 255 -> Render
Ok(match minor(dev) >> 6 {
0 => Self::Primary,
1 => Self::Control,
2 => Self::Render,
_ => return Err(CreateDrmNodeError::NotDrmNode),
})
}

#[cfg(not(target_os = "linux"))]
fn minor_base(&self) -> u32 {
fn minor_index(&self) -> u32 {
match self {
NodeType::Primary => 0,
NodeType::Control => 64,
NodeType::Render => 128,
NodeType::Control => 1,
NodeType::Render => 2,
}
}

#[cfg(not(target_os = "linux"))]
fn minor_base(&self) -> u32 {
self.minor_index() << 6
}
}

impl Display for NodeType {
Expand Down

0 comments on commit 7c47617

Please sign in to comment.