On Mon, Jun 08, 2026 at 01:19:08PM +0200, Nicolas Frattaroli wrote:
> The HDMI state helpers will count down from the max bpc to 8 in steps of
> 2, trying each value as a possible output bpc. This goes awry if max bpc
> is restricted by userspace to an odd number with the "max bpc" connector
> property.
> 
> Prevent this, without introducing any additional bpc format trial steps,
> by simply subtracting max_bpc modulo 2 from max_bpc as the starting
> point for the for loop.
> 
> Additionally, add a KUnit test to validate the handling of this.
> 
> Fixes: 26ff1c38fc29 ("drm/connector: hdmi: Compute bpc and format 
> automatically")
> Signed-off-by: Nicolas Frattaroli <[email protected]>
> ---
>  drivers/gpu/drm/display/drm_hdmi_state_helper.c    |  2 +-
>  drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c | 71 
> ++++++++++++++++++++++
>  2 files changed, 72 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/display/drm_hdmi_state_helper.c 
> b/drivers/gpu/drm/display/drm_hdmi_state_helper.c
> index 8303475ec021..9fbf88054ad8 100644
> --- a/drivers/gpu/drm/display/drm_hdmi_state_helper.c
> +++ b/drivers/gpu/drm/display/drm_hdmi_state_helper.c
> @@ -648,7 +648,7 @@ hdmi_compute_format_bpc(const struct drm_connector 
> *connector,
>       unsigned int bpc;
>       int ret;
>  
> -     for (bpc = max_bpc; bpc >= 8; bpc -= 2) {
> +     for (bpc = max_bpc - max_bpc % 2; bpc >= 8; bpc -= 2) {

bpc = round_down(max_bpc, 2) (or rounddown) would be more readable here.

Looks good otherwise, once fixed
Reviewed-by: Maxime Ripard <[email protected]>

Maxime

Attachment: signature.asc
Description: PGP signature

Reply via email to