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 <[email protected]> --- Changes in v2: - Updated to use the new page_align() Option<usize> return value - Prerequisite patch: https://lore.kernel.org/rust-for-linux/[email protected]/T/#u Changes in v3: - Add back missing semi-colon after ok_or(). - Reword commit message to be more concise. - Link to v2: https://lore.kernel.org/rust-for-linux/[email protected]/T/#u drivers/gpu/drm/nova/gem.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/nova/gem.rs b/drivers/gpu/drm/nova/gem.rs index 2760ba4f3450..6d715044f1fa 100644 --- a/drivers/gpu/drm/nova/gem.rs +++ b/drivers/gpu/drm/nova/gem.rs @@ -3,6 +3,7 @@ use kernel::{ drm, drm::{gem, gem::BaseObject}, + page::page_align, prelude::*, sync::aref::ARef, }; @@ -27,11 +28,7 @@ fn new(_dev: &NovaDevice, _size: usize) -> impl PinInit<Self, Error> { impl NovaObject { /// Create a new DRM GEM object. pub(crate) fn new(dev: &NovaDevice, size: usize) -> Result<ARef<gem::Object<Self>>> { - let aligned_size = size.next_multiple_of(1 << 12); - - if size == 0 || size > aligned_size { - return Err(EINVAL); - } + let aligned_size = page_align(size).ok_or(EINVAL)?; gem::Object::new(dev, aligned_size) } base-commit: 37bb2e7217b01404e2abf9d90d8e5705a5603b52 -- 2.52.0
