]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
habanalabs: fix VA range calculation
authorOhad Sharabi <osharabi@habana.ai>
Sun, 20 Nov 2022 13:12:26 +0000 (15:12 +0200)
committerOded Gabbay <ogabbay@kernel.org>
Wed, 23 Nov 2022 14:54:10 +0000 (16:54 +0200)
Current implementation is fixing the page size to PAGE_SIZE whereas the
input page size may be different.

Signed-off-by: Ohad Sharabi <osharabi@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
drivers/misc/habanalabs/common/memory.c

index 541e1b6a2176dfd822f9f9a5cfcdadc07d1028b4..7c5c18be294a8298eb90e620aec193b22f24d117 100644 (file)
@@ -2508,24 +2508,20 @@ static int va_range_init(struct hl_device *hdev, struct hl_va_range **va_ranges,
 
        /*
         * PAGE_SIZE alignment
-        * it is the callers responsibility to align the addresses if the
+        * it is the caller's responsibility to align the addresses if the
         * page size is not a power of 2
         */
 
        if (is_power_of_2(page_size)) {
-               if (start & (PAGE_SIZE - 1)) {
-                       start &= PAGE_MASK;
-                       start += PAGE_SIZE;
-               }
+               start = round_up(start, page_size);
 
                /*
                 * The end of the range is inclusive, hence we need to align it
                 * to the end of the last full page in the range. For example if
                 * end = 0x3ff5 with page size 0x1000, we need to align it to
-                * 0x2fff. The remainig 0xff5 bytes do not form a full page.
+                * 0x2fff. The remaining 0xff5 bytes do not form a full page.
                 */
-               if ((end + 1) & (PAGE_SIZE - 1))
-                       end = ((end + 1) & PAGE_MASK) - 1;
+               end = round_down(end + 1, page_size) - 1;
        }
 
        if (start >= end) {