AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amd/display: Fix logical vs bitwise bug in get_embedded_panel_info_v2_1()
@ 2025-10-31 13:02 Dan Carpenter
  2025-11-21 19:36 ` Alex Hung
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2025-10-31 13:02 UTC (permalink / raw)
  To: Harry Wentland, Harshit Mogalapalli
  Cc: Leo Li, Rodrigo Siqueira, Alex Deucher, Christian König,
	David Airlie, Simona Vetter, Hamish Claxton, Aurabindo Pillai,
	Zaeem Mohamed, Michael Strauss, amd-gfx, dri-devel, linux-kernel,
	kernel-janitors

The .H_SYNC_POLARITY and .V_SYNC_POLARITY variables are 1 bit bitfields
of a u32.  The ATOM_HSYNC_POLARITY define is 0x2 and the
ATOM_VSYNC_POLARITY is 0x4.  When we do a bitwise negate of 0, 2, or 4
then the last bit is always 1 so this code always sets .H_SYNC_POLARITY
and .V_SYNC_POLARITY to true.

This code is instead intended to check if the ATOM_HSYNC_POLARITY or
ATOM_VSYNC_POLARITY flags are set and reverse the result.  In other
words, it's supposed to be a logical negate instead of a bitwise negate.

Fixes: ae79c310b1a6 ("drm/amd/display: Add DCE12 bios parser support")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
Please note that I have not tested this.  It's straight forward enough to
see that logical negate was intended, but it's always good to test things
as well.

Harshit and I only recently created this static checker warning.

 drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c b/drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c
index 04eb647acc4e..550a9f1d03f8 100644
--- a/drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c
+++ b/drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c
@@ -1480,10 +1480,10 @@ static enum bp_result get_embedded_panel_info_v2_1(
 	/* not provided by VBIOS */
 	info->lcd_timing.misc_info.HORIZONTAL_CUT_OFF = 0;
 
-	info->lcd_timing.misc_info.H_SYNC_POLARITY = ~(uint32_t) (lvds->lcd_timing.miscinfo
-			& ATOM_HSYNC_POLARITY);
-	info->lcd_timing.misc_info.V_SYNC_POLARITY = ~(uint32_t) (lvds->lcd_timing.miscinfo
-			& ATOM_VSYNC_POLARITY);
+	info->lcd_timing.misc_info.H_SYNC_POLARITY = !(lvds->lcd_timing.miscinfo &
+						       ATOM_HSYNC_POLARITY);
+	info->lcd_timing.misc_info.V_SYNC_POLARITY = !(lvds->lcd_timing.miscinfo &
+						       ATOM_VSYNC_POLARITY);
 
 	/* not provided by VBIOS */
 	info->lcd_timing.misc_info.VERTICAL_CUT_OFF = 0;
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drm/amd/display: Fix logical vs bitwise bug in get_embedded_panel_info_v2_1()
  2025-10-31 13:02 [PATCH] drm/amd/display: Fix logical vs bitwise bug in get_embedded_panel_info_v2_1() Dan Carpenter
@ 2025-11-21 19:36 ` Alex Hung
  0 siblings, 0 replies; 2+ messages in thread
From: Alex Hung @ 2025-11-21 19:36 UTC (permalink / raw)
  To: Dan Carpenter, Harry Wentland, Harshit Mogalapalli
  Cc: Leo Li, Rodrigo Siqueira, Alex Deucher, Christian König,
	David Airlie, Simona Vetter, Hamish Claxton, Aurabindo Pillai,
	Zaeem Mohamed, Michael Strauss, amd-gfx, dri-devel, linux-kernel,
	kernel-janitors

This patch passes this week's promotion test.

Reviewed-by: Alex Hung <alex.hung@amd.com>

On 10/31/25 07:02, Dan Carpenter wrote:
> The .H_SYNC_POLARITY and .V_SYNC_POLARITY variables are 1 bit bitfields
> of a u32.  The ATOM_HSYNC_POLARITY define is 0x2 and the
> ATOM_VSYNC_POLARITY is 0x4.  When we do a bitwise negate of 0, 2, or 4
> then the last bit is always 1 so this code always sets .H_SYNC_POLARITY
> and .V_SYNC_POLARITY to true.
> 
> This code is instead intended to check if the ATOM_HSYNC_POLARITY or
> ATOM_VSYNC_POLARITY flags are set and reverse the result.  In other
> words, it's supposed to be a logical negate instead of a bitwise negate.
> 
> Fixes: ae79c310b1a6 ("drm/amd/display: Add DCE12 bios parser support")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
> Please note that I have not tested this.  It's straight forward enough to
> see that logical negate was intended, but it's always good to test things
> as well.
> 
> Harshit and I only recently created this static checker warning.
> 
>   drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c b/drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c
> index 04eb647acc4e..550a9f1d03f8 100644
> --- a/drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c
> +++ b/drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c
> @@ -1480,10 +1480,10 @@ static enum bp_result get_embedded_panel_info_v2_1(
>   	/* not provided by VBIOS */
>   	info->lcd_timing.misc_info.HORIZONTAL_CUT_OFF = 0;
>   
> -	info->lcd_timing.misc_info.H_SYNC_POLARITY = ~(uint32_t) (lvds->lcd_timing.miscinfo
> -			& ATOM_HSYNC_POLARITY);
> -	info->lcd_timing.misc_info.V_SYNC_POLARITY = ~(uint32_t) (lvds->lcd_timing.miscinfo
> -			& ATOM_VSYNC_POLARITY);
> +	info->lcd_timing.misc_info.H_SYNC_POLARITY = !(lvds->lcd_timing.miscinfo &
> +						       ATOM_HSYNC_POLARITY);
> +	info->lcd_timing.misc_info.V_SYNC_POLARITY = !(lvds->lcd_timing.miscinfo &
> +						       ATOM_VSYNC_POLARITY);
>   
>   	/* not provided by VBIOS */
>   	info->lcd_timing.misc_info.VERTICAL_CUT_OFF = 0;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-11-21 19:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-31 13:02 [PATCH] drm/amd/display: Fix logical vs bitwise bug in get_embedded_panel_info_v2_1() Dan Carpenter
2025-11-21 19:36 ` Alex Hung

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox