[RFC PATCH 2/9] rust: drm: gem: add method to return DmaResv from GEMObject
Björn Roy Baron
bjorn3_gh at protonmail.com
Wed Mar 22 19:45:34 UTC 2023
On Friday, March 17th, 2023 at 13:12, Maíra Canal <mcanal at igalia.com> wrote:
> A GEMObject, related to struct drm_gem_object, holds a pointer
> to reservation object associated with the this GEM object. Therefore,
> expose this reservation object through the DmaResv safe abstraction.
>
> Signed-off-by: Maíra Canal <mcanal at igalia.com>
> ---
> rust/kernel/drm/gem/mod.rs | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs
> index c4a42bb2f718..dae95e5748a7 100644
> --- a/rust/kernel/drm/gem/mod.rs
> +++ b/rust/kernel/drm/gem/mod.rs
> @@ -11,6 +11,7 @@ use alloc::boxed::Box;
>
> use crate::{
> bindings,
> + dma_resv::DmaResv,
> drm::{device, drv, file},
> error::{to_result, Result},
> prelude::*,
> @@ -136,6 +137,12 @@ pub trait BaseObject: IntoGEMObject {
> self.gem_obj().size
> }
>
> + /// Returns the pointer to reservation object associated with this GEM object.
> + fn resv(&self) -> DmaResv {
> + // SAFETY: Every GEM object holds a reference to a reservation object
> + unsafe { DmaResv::from_raw(self.gem_obj().resv) }
> + }
There is nothing ensuring that DmaResv doesn't outlive self and thus may have been deallocated. You could change DmaResv to be a newtype around UnsafeCell<dma_resv> and then return an &DmaResv here. This way &DmaResv can't outlive &self.
> +
> /// Sets the exportable flag, which controls whether the object can be exported via PRIME.
> fn set_exportable(&mut self, exportable: bool) {
> self.mut_gem_obj().exportable = exportable;
> --
> 2.39.2
Cheers,
Bjorn
More information about the dri-devel
mailing list