Skip to content

Commit 10549d9

Browse files
WhatAmISupposedToPutHerejannau
authored andcommitted
rust: device: WIP(?): Add get_drvdata for AOP series
Signed-off-by: Sasha Finkelstein <fnkl.kernel@gmail.com> Signed-off-by: Janne Grunau <j@jannau.net>
1 parent 6646dfa commit 10549d9

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

rust/helpers/device.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
#include <linux/device.h>
44

5+
void *rust_helper_dev_get_drvdata(struct device *dev)
6+
{
7+
return dev_get_drvdata(dev);
8+
}
9+
510
int rust_helper_devm_add_action(struct device *dev,
611
void (*action)(void *),
712
void *data)

rust/kernel/device.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ impl<Ctx: DeviceContext> Device<Ctx> {
9090
}
9191
}
9292

93+
/// Returns the driver_data pointer.
94+
pub fn get_drvdata<T>(&self) -> *mut T {
95+
// SAFETY: dev_get_drvdata returns a field of the device,
96+
// pointer to which is valid by type invariant
97+
unsafe { bindings::dev_get_drvdata(self.as_raw()) as *mut T }
98+
}
99+
93100
/// Convert a raw C `struct device` pointer to a `&'a Device`.
94101
///
95102
/// # Safety

0 commit comments

Comments
 (0)