[PATCH] drm/amd/display: Interpret log_2(0) as 0

Harry Wentland harry.wentland at amd.com
Wed Oct 21 16:09:22 UTC 2020


Even though log(0) is technically undefined our code assumes that
log_2(0) is 0. This mirrors the current behavior of our log_2
implementation on non-Linux platforms.

Signed-off-by: Harry Wentland <harry.wentland at amd.com>
---

What's num_pkrs value is upstream Mesa providing for CHIP_VANGOGH?

I saw that problem at bringup with an internal Mesa and had this fix
for it.

Harry

 drivers/gpu/drm/amd/display/dc/basics/conversion.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/dc/basics/conversion.h b/drivers/gpu/drm/amd/display/dc/basics/conversion.h
index ade785c4fdc7..da9883ec7b1c 100644
--- a/drivers/gpu/drm/amd/display/dc/basics/conversion.h
+++ b/drivers/gpu/drm/amd/display/dc/basics/conversion.h
@@ -40,7 +40,11 @@ void convert_float_matrix(
 
 static inline unsigned int log_2(unsigned int num)
 {
-	return ilog2(num);
+	/*
+	 * Technically log(0) is undefined, but our code is structured
+	 * in a way that assumes log(0) = 0
+	 */
+	return num ? ilog2(num) : num;
 }
 
 #endif
-- 
2.28.0



More information about the amd-gfx mailing list