]> git.baikalelectronics.ru Git - kernel.git/commit
drm/i915/gvt: Prevent divided by zero when calculating refresh rate
authorColin Xu <colin.xu@intel.com>
Fri, 16 Apr 2021 08:33:55 +0000 (16:33 +0800)
committerZhenyu Wang <zhenyuw@linux.intel.com>
Thu, 29 Apr 2021 09:00:09 +0000 (17:00 +0800)
commite3b90ce6b976013510399e2fde8ac63592e26386
treec75d5bf58c139bbb52fdbc87008fd9dbd3b7b5d8
parent86723d42058291e46fb1591fef74d7d397c085ca
drm/i915/gvt: Prevent divided by zero when calculating refresh rate

To get refresh rate as vblank timer period and keep the precision, the
calculation of rate is multiplied by 1000. However old logic was using:
rate = pixel clock / (h * v / 1000). When the h/v total is invalid, like
all 0, h * v / 1000 will be rounded to 0, which leads to a divided by 0
fault.

0 H/V are already checked above. Instead of divide after divide, refine
the calculation to divide after multiply: "pixel clock * 1000 / (h * v)"
Guest driver should guarantee the correctness of the timing regs' value.

Fixes: 2190032763cd ("drm/i915/gvt: Get accurate vGPU virtual display refresh rate from vreg")
Reported-by: Zhenyu Wang <zhenyuw@linux.intel.com>
Signed-off-by: Colin Xu <colin.xu@intel.com>
Signed-off-by: Zhenyu Wang <zhenyuw@linux.intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20210416083355.159305-1-colin.xu@intel.com
Reviewed-by: Zhenyu Wang <zhenyuw@linux.intel.com>
drivers/gpu/drm/i915/gvt/handlers.c