mirror of
https://github.com/torvalds/linux.git
synced 2026-04-19 15:24:02 -04:00
Use page::page_align for GEM object memory allocation to ensure the allocation is page aligned. This is important on systems where the default page size is not 4k. Such as 16k or 64k aarch64 systems. This change uses the updated page_align() function which returns Option<usize> for overflow safety. (See "rust: Return Option from page_align and ensure no usize overflow"). Signed-off-by: Brendan Shephard <bshephar@bne-home.net> Link: https://patch.msgid.link/20251215083416.266469-1-bshephar@bne-home.net [ Import page module only. - Danilo ] Signed-off-by: Danilo Krummrich <dakr@kernel.org>
48 lines
1.1 KiB
Rust
48 lines
1.1 KiB
Rust
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
use kernel::{
|
|
drm,
|
|
drm::{gem, gem::BaseObject},
|
|
page,
|
|
prelude::*,
|
|
sync::aref::ARef,
|
|
};
|
|
|
|
use crate::{
|
|
driver::{NovaDevice, NovaDriver},
|
|
file::File,
|
|
};
|
|
|
|
/// GEM Object inner driver data
|
|
#[pin_data]
|
|
pub(crate) struct NovaObject {}
|
|
|
|
impl gem::DriverObject for NovaObject {
|
|
type Driver = NovaDriver;
|
|
|
|
fn new(_dev: &NovaDevice, _size: usize) -> impl PinInit<Self, Error> {
|
|
try_pin_init!(NovaObject {})
|
|
}
|
|
}
|
|
|
|
impl NovaObject {
|
|
/// Create a new DRM GEM object.
|
|
pub(crate) fn new(dev: &NovaDevice, size: usize) -> Result<ARef<gem::Object<Self>>> {
|
|
if size == 0 {
|
|
return Err(EINVAL);
|
|
}
|
|
let aligned_size = page::page_align(size).ok_or(EINVAL)?;
|
|
|
|
gem::Object::new(dev, aligned_size)
|
|
}
|
|
|
|
/// Look up a GEM object handle for a `File` and return an `ObjectRef` for it.
|
|
#[inline]
|
|
pub(crate) fn lookup_handle(
|
|
file: &drm::File<File>,
|
|
handle: u32,
|
|
) -> Result<ARef<gem::Object<Self>>> {
|
|
gem::Object::lookup_handle(file, handle)
|
|
}
|
|
}
|