staging: vchiq_arm: introduce is_adjacent_block
authorStefan Wahren <stefan.wahren@i2se.com>
Sun, 23 Jan 2022 20:02:08 +0000 (21:02 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 25 Jan 2022 15:30:15 +0000 (16:30 +0100)
The check for an adjacent block is hard to read. So move it into a separate
inline function.

Reviewed-by: Nicolas Saenz Julienne <nsaenz@kernel.org>
Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
Link: https://lore.kernel.org/r/1642968143-19281-4-git-send-email-stefan.wahren@i2se.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c

index 6759a62..9748044 100644 (file)
@@ -189,6 +189,20 @@ cleanup_pagelistinfo(struct vchiq_pagelist_info *pagelistinfo)
                          pagelistinfo->pagelist, pagelistinfo->dma_addr);
 }
 
+static inline bool
+is_adjacent_block(u32 *addrs, u32 addr, unsigned int k)
+{
+       u32 tmp;
+
+       if (!k)
+               return false;
+
+       tmp = (addrs[k - 1] & PAGE_MASK) +
+             (((addrs[k - 1] & ~PAGE_MASK) + 1) << PAGE_SHIFT);
+
+       return tmp == (addr & PAGE_MASK);
+}
+
 /* There is a potential problem with partial cache lines (pages?)
  * at the ends of the block when reading. If the CPU accessed anything in
  * the same line (page?) then it may have pulled old data into the cache,
@@ -349,10 +363,7 @@ create_pagelist(char *buf, char __user *ubuf,
                WARN_ON(len == 0);
                WARN_ON(i && (i != (dma_buffers - 1)) && (len & ~PAGE_MASK));
                WARN_ON(i && (addr & ~PAGE_MASK));
-               if (k > 0 &&
-                   ((addrs[k - 1] & PAGE_MASK) +
-                    (((addrs[k - 1] & ~PAGE_MASK) + 1) << PAGE_SHIFT))
-                   == (addr & PAGE_MASK))
+               if (is_adjacent_block(addrs, addr, k))
                        addrs[k - 1] += ((len + PAGE_SIZE - 1) >> PAGE_SHIFT);
                else
                        addrs[k++] = (addr & PAGE_MASK) |