Skip to content

Commit

Permalink
Fix style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisduerr committed Sep 11, 2024
1 parent 40cdaf1 commit 74d2633
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl DrmNode {
}

/// Creates a DRM node from a [`dev_t`].
pub fn from_dev_id(dev: dev_t) -> Result<DrmNode, CreateDrmNodeError> {
pub fn from_dev_id(dev: dev_t) -> Result<Self, CreateDrmNodeError> {
if !is_device_drm(dev) {
return Err(CreateDrmNodeError::NotDrmNode);
}
Expand Down Expand Up @@ -153,6 +153,15 @@ impl NodeType {
NodeType::Render => RENDER_NAME,
}
}

#[cfg(any(target_os = "freebsd", target_os = "openbsd"))]
fn get_minor_base(&self) -> u32 {
match self {
NodeType::Primary => 0,
NodeType::Control => 64,
NodeType::Render => 128,
}
}
}

impl Display for NodeType {
Expand Down Expand Up @@ -323,8 +332,10 @@ fn dev_path(dev: dev_t, ty: NodeType) -> io::Result<PathBuf> {
let suffix = dev_name.trim_start_matches(|c: char| !c.is_numeric());
if let Ok(old_id) = suffix.parse::<u32>() {
let id_mask = 0b11_1111;
let id = old_id & id_mask + get_minor_base(ty);
let path = PathBuf::new("/dev/dri").join(ty.minor_name_prefix()).join(id);
let id = old_id & id_mask + ty.get_minor_base();
let path = PathBuf::new("/dev/dri")
.join(ty.minor_name_prefix())
.join(id);
if path.exists() {
return Ok(path);
}
Expand All @@ -342,6 +353,7 @@ fn dev_path(dev: dev_t, ty: NodeType) -> io::Result<PathBuf> {
))
}

/// Returns the path of a specific type of node from the DRM device described by major and minor device numbers.
#[cfg(target_os = "openbsd")]
fn dev_path(dev: dev_t, ty: NodeType) -> io::Result<PathBuf> {
use std::io::ErrorKind;
Expand All @@ -355,7 +367,7 @@ fn dev_path(dev: dev_t, ty: NodeType) -> io::Result<PathBuf> {

let old_id = minor(dev);
let id_mask = 0b11_1111;
let id = old_id & id_mask + get_minor_base(ty);
let id = old_id & id_mask + ty.get_minor_base();
let path = PathBuf::from("/dev/dri", ty.minor_name_prefix(), id);
if path.exists() {
return Ok(path);
Expand All @@ -371,12 +383,3 @@ fn dev_path(dev: dev_t, ty: NodeType) -> io::Result<PathBuf> {
),
))
}

#[cfg(any(target_os = "freebsd", target_os = "openbsd"))]
fn get_minor_base(type_: NodeType) -> u32 {
match type_ {
NodeType::Primary => 0,
NodeType::Control => 64,
NodeType::Render => 128,
}
}

0 comments on commit 74d2633

Please sign in to comment.