Skip to content

Commit

Permalink
Add (major, minor, patchlevel) to Driver get_version() probe
Browse files Browse the repository at this point in the history
`struct drm_version` contains actual version fields, beyond the strings
for the driver name, deveice description and date string.  Add a tuple
field for this to `struct Driver`.
  • Loading branch information
MarijnS95 committed Aug 14, 2024
1 parent 0db7924 commit bee5439
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 2 additions & 6 deletions drm-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ pub fn get_version(
mut desc_buf: Option<&mut Vec<i8>>,
) -> io::Result<drm_version> {
let mut sizes = drm_version::default();
unsafe {
ioctl::get_version(fd, &mut sizes)?;
}
unsafe { ioctl::get_version(fd, &mut sizes) }?;

map_reserve!(name_buf, sizes.name_len as usize);
map_reserve!(date_buf, sizes.date_len as usize);
Expand All @@ -178,9 +176,7 @@ pub fn get_version(
..Default::default()
};

unsafe {
ioctl::get_version(fd, &mut version)?;
}
unsafe { ioctl::get_version(fd, &mut version) }?;

map_set!(name_buf, version.name_len as usize);
map_set!(date_buf, version.date_len as usize);
Expand Down
12 changes: 10 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,24 @@ pub trait Device: AsFd {
let mut date = Vec::new();
let mut desc = Vec::new();

let _ = drm_ffi::get_version(
let v = drm_ffi::get_version(
self.as_fd(),
Some(&mut name),
Some(&mut date),
Some(&mut desc),
)?;

let version = (v.version_major, v.version_minor, v.version_patchlevel);
let name = OsString::from_vec(unsafe { transmute_vec(name) });
let date = OsString::from_vec(unsafe { transmute_vec(date) });
let desc = OsString::from_vec(unsafe { transmute_vec(desc) });

let driver = Driver { name, date, desc };
let driver = Driver {
version,
name,
date,
desc,
};

Ok(driver)
}
Expand Down Expand Up @@ -238,6 +244,8 @@ pub struct AuthToken(u32);
/// Driver version of a device.
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct Driver {
/// Version of the driver in `(major, minor, patchlevel)` format
pub version: (i32, i32, i32),
/// Name of the driver
pub name: OsString,
/// Date driver was published
Expand Down

0 comments on commit bee5439

Please sign in to comment.