diff mbox series

drm/imagination: Ensure PVR_MIPS_PT_PAGE_COUNT is never zero

Message ID 489aa9ab-3de1-4bfb-aaae-b093536d16ce@imgtec.com (mailing list archive)
State New, archived
Headers show
Series drm/imagination: Ensure PVR_MIPS_PT_PAGE_COUNT is never zero | expand

Commit Message

Matt Coster April 23, 2024, 4:09 p.m. UTC
When the host page size was more than 4 times larger than the FW page
size, this macro evaluated to zero resulting in zero-sized arrays.

Use DIV_ROUND_UP() to ensure the correct behavior.

Reported-by: 20240228012313.5934-1-yaolu@kylinos.cn
Closes: https://lore.kernel.org/dri-devel/20240228012313.5934-1-yaolu@kylinos.cn
Fixes: 927f3e0253c1 ("drm/imagination: Implement MIPS firmware processor and MMU support")
Signed-off-by: Matt Coster <matt.coster@imgtec.com>
---
 drivers/gpu/drm/imagination/pvr_fw_mips.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)


base-commit: e95752752eaf06c860811ac5ddf9badf6c1b43ca

Comments

Frank Binns April 24, 2024, 10:51 a.m. UTC | #1
On Tue, 2024-04-23 at 16:09 +0000, Matt Coster wrote:
> When the host page size was more than 4 times larger than the FW page
> size, this macro evaluated to zero resulting in zero-sized arrays.
> 
> Use DIV_ROUND_UP() to ensure the correct behavior.
> 
> Reported-by: 20240228012313.5934-1-yaolu@kylinos.cn
> Closes: https://lore.kernel.org/dri-devel/20240228012313.5934-1-yaolu@kylinos.cn
> Fixes: 927f3e0253c1 ("drm/imagination: Implement MIPS firmware processor and MMU support")
> Signed-off-by: Matt Coster <matt.coster@imgtec.com>

Reviewed-by: Frank Binns <frank.binns@imgtec.com>

> ---
>  drivers/gpu/drm/imagination/pvr_fw_mips.h | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/imagination/pvr_fw_mips.h b/drivers/gpu/drm/imagination/pvr_fw_mips.h
> index 408dbe63a90c..a0c5c41c8aa2 100644
> --- a/drivers/gpu/drm/imagination/pvr_fw_mips.h
> +++ b/drivers/gpu/drm/imagination/pvr_fw_mips.h
> @@ -7,13 +7,14 @@
>  #include "pvr_rogue_mips.h"
>  
>  #include <asm/page.h>
> +#include <linux/math.h>
>  #include <linux/types.h>
>  
>  /* Forward declaration from pvr_gem.h. */
>  struct pvr_gem_object;
>  
> -#define PVR_MIPS_PT_PAGE_COUNT ((ROGUE_MIPSFW_MAX_NUM_PAGETABLE_PAGES * ROGUE_MIPSFW_PAGE_SIZE_4K) \
> -				>> PAGE_SHIFT)
> +#define PVR_MIPS_PT_PAGE_COUNT DIV_ROUND_UP(ROGUE_MIPSFW_MAX_NUM_PAGETABLE_PAGES * ROGUE_MIPSFW_PAGE_SIZE_4K, PAGE_SIZE)
> +
>  /**
>   * struct pvr_fw_mips_data - MIPS-specific data
>   */
> 
> base-commit: e95752752eaf06c860811ac5ddf9badf6c1b43ca
diff mbox series

Patch

diff --git a/drivers/gpu/drm/imagination/pvr_fw_mips.h b/drivers/gpu/drm/imagination/pvr_fw_mips.h
index 408dbe63a90c..a0c5c41c8aa2 100644
--- a/drivers/gpu/drm/imagination/pvr_fw_mips.h
+++ b/drivers/gpu/drm/imagination/pvr_fw_mips.h
@@ -7,13 +7,14 @@ 
 #include "pvr_rogue_mips.h"
 
 #include <asm/page.h>
+#include <linux/math.h>
 #include <linux/types.h>
 
 /* Forward declaration from pvr_gem.h. */
 struct pvr_gem_object;
 
-#define PVR_MIPS_PT_PAGE_COUNT ((ROGUE_MIPSFW_MAX_NUM_PAGETABLE_PAGES * ROGUE_MIPSFW_PAGE_SIZE_4K) \
-				>> PAGE_SHIFT)
+#define PVR_MIPS_PT_PAGE_COUNT DIV_ROUND_UP(ROGUE_MIPSFW_MAX_NUM_PAGETABLE_PAGES * ROGUE_MIPSFW_PAGE_SIZE_4K, PAGE_SIZE)
+
 /**
  * struct pvr_fw_mips_data - MIPS-specific data
  */