Skip to contentSkip to conversation

drm/amd/display: Fix warning about overflow

PATCH Superseded Harry Wentland 3 participants 5 messages Oct 12, 2017 – Oct 13, 2017 4 messages not in the archive

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amd/display: Fix warning about overflow

We're overflowing the last bit. Cast it explicitly

---
 drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c +1 -1
index cb94e18cc455..715dc789bb24 100644
@@ -1047,7 +1047,7 @@ static enum bp_result get_embedded_panel_info_v2_1(
 		lvds->lcd_timing.miscinfo & ATOM_V_REPLICATIONBY2;
 	info->lcd_timing.misc_info.COMPOSITE_SYNC =
 		lvds->lcd_timing.miscinfo & ATOM_COMPOSITESYNC;
-	info->lcd_timing.misc_info.INTERLACE =
+	info->lcd_timing.misc_info.INTERLACE = (uint32_t)
 		lvds->lcd_timing.miscinfo & ATOM_INTERLACE;
 
 	/* not provided by VBIOS*/
Signature · 6 lines
2.14.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 20171012175442.4298-1-harry.wentland-5C7GfCeVMHo@public.gmane.org

#2 lore raw
Quoted 12 lines · Harry Wentland

We're overflowing the last bit. Cast it explicitly

---
 drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c +0 -0
index cb94e18cc455..715dc789bb24 100644

drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c static enum bp_result get_embedded_panel_info_v2_1( · line 1051

Quoted 6 lines
drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c +1 -1
@@ -1047,7 +1047,7 @@ static enum bp_result get_embedded_panel_info_v2_1(
 		lvds->lcd_timing.miscinfo & ATOM_V_REPLICATIONBY2;
 	info->lcd_timing.misc_info.COMPOSITE_SYNC =
 		lvds->lcd_timing.miscinfo & ATOM_COMPOSITESYNC;
-	info->lcd_timing.misc_info.INTERLACE =
+	info->lcd_timing.misc_info.INTERLACE = (uint32_t)
 		lvds->lcd_timing.miscinfo & ATOM_INTERLACE;

I wasn't sure offhand, so I had to write a little test program, but it looks like this doesn't work as intended:

(lvds->lcd_timing.miscinfo & ATOM_INTERLACE) is an unsigned 16-bit value, which is either 0x80 (ATOM_INTERLACE) or 0. Assigning that to the unsigned 1-bit field info->lcd_timing.misc_info.INTERLACE always results in 0. Casting the 16-bit value to 32 bits doesn't change that.

I think what's intended here is something like

	info->lcd_timing.misc_info.INTERLACE =
		(lvds->lcd_timing.miscinfo & ATOM_INTERLACE) != 0;

Looks like there's the same problem with other fields of info->lcd_timing.misc_info above.

Another possible solution is making the fields of struct misc_info bool instead of uint32_t.

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): c112fc85-6fb5-9f1a-d495-e2f87777e437-otUistvHUpPR7s880joybQ@public.gmane.org

#4 lore raw

Am 13.10.2017 um 10:08 schrieb Michel Dänzer:

Quoted 8 lines · Harry Wentland
Quoted 7 lines

We're overflowing the last bit. Cast it explicitly

---
  drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c static enum bp_result get_embedded_panel_info_v2_1( · line 1051

Quoted 11 lines
drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c +1 -1
index cb94e18cc455..715dc789bb24 100644
@@ -1047,7 +1047,7 @@ static enum bp_result get_embedded_panel_info_v2_1(
  		lvds->lcd_timing.miscinfo & ATOM_V_REPLICATIONBY2;
  	info->lcd_timing.misc_info.COMPOSITE_SYNC =
  		lvds->lcd_timing.miscinfo & ATOM_COMPOSITESYNC;
-	info->lcd_timing.misc_info.INTERLACE =
+	info->lcd_timing.misc_info.INTERLACE = (uint32_t)
  		lvds->lcd_timing.miscinfo & ATOM_INTERLACE;

I wasn't sure offhand, so I had to write a little test program, but it looks like this doesn't work as intended: (lvds->lcd_timing.miscinfo & ATOM_INTERLACE) is an unsigned 16-bit value, which is either 0x80 (ATOM_INTERLACE) or 0. Assigning that to the unsigned 1-bit field info->lcd_timing.misc_info.INTERLACE always results in 0. Casting the 16-bit value to 32 bits doesn't change that. I think what's intended here is something like info->lcd_timing.misc_info.INTERLACE = (lvds->lcd_timing.miscinfo & ATOM_INTERLACE) != 0; Looks like there's the same problem with other fields of info->lcd_timing.misc_info above. Another possible solution is making the fields of struct misc_info bool instead of uint32_t.

While your approach works as well IIRC converting an arbitrary value into a boolean is usually done with "!!".

E.g. that should look like:

    info->lcd_timing.misc_info.INTERLACE =
        !!(lvds->lcd_timing.miscinfo & ATOM_INTERLACE);

Regards,
Christian.
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 09362d54-c669-d854-6b74-a6c823c31bb1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#6 lore raw
Quoted 34 lines · Christian König

Am 13.10.2017 um 10:08 schrieb Michel Dänzer:

Quoted 24 lines · Harry Wentland
Quoted 13 lines

We're overflowing the last bit. Cast it explicitly

---
  drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c +0 -0
index cb94e18cc455..715dc789bb24 100644
@@ -1047,7 +1047,7 @@ static enum bp_result
Quoted 7 lines

get_embedded_panel_info_v2_1( lvds->lcd_timing.miscinfo & ATOM_V_REPLICATIONBY2; info->lcd_timing.misc_info.COMPOSITE_SYNC = lvds->lcd_timing.miscinfo & ATOM_COMPOSITESYNC; -    info->lcd_timing.misc_info.INTERLACE =
+    info->lcd_timing.misc_info.INTERLACE = (uint32_t) lvds->lcd_timing.miscinfo & ATOM_INTERLACE;

I wasn't sure offhand, so I had to write a little test program, but it looks like this doesn't work as intended: (lvds->lcd_timing.miscinfo & ATOM_INTERLACE) is an unsigned 16-bit value, which is either 0x80

Quoted 8 lines

(ATOM_INTERLACE) or 0. Assigning that to the unsigned 1-bit field info->lcd_timing.misc_info.INTERLACE always results in 0. Casting the 16-bit value to 32 bits doesn't change that. I think what's intended here is something like info->lcd_timing.misc_info.INTERLACE = (lvds->lcd_timing.miscinfo & ATOM_INTERLACE) != 0; Looks like there's the same problem with other fields of info->lcd_timing.misc_info above. Another possible solution is making the fields of struct misc_info bool instead of uint32_t.

Quoted 7 lines

While your approach works as well IIRC converting an arbitrary value into a boolean is usually done with "!!".

E.g. that should look like:

    info->lcd_timing.misc_info.INTERLACE = !!(lvds->lcd_timing.miscinfo & ATOM_INTERLACE);

Right, that works as well, thanks.

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): a5be2e34-787b-3b2d-ed26-4df1fe14534b-otUistvHUpPR7s880joybQ@public.gmane.org

#8 lore raw
Quoted 38 lines · Michel Dänzer
Quoted 37 lines · Christian König

Am 13.10.2017 um 10:08 schrieb Michel Dänzer:

Quoted 24 lines · Harry Wentland
Quoted 13 lines

We're overflowing the last bit. Cast it explicitly

---
  drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c +0 -0
index cb94e18cc455..715dc789bb24 100644
@@ -1047,7 +1047,7 @@ static enum bp_result
Quoted 7 lines

get_embedded_panel_info_v2_1( lvds->lcd_timing.miscinfo & ATOM_V_REPLICATIONBY2; info->lcd_timing.misc_info.COMPOSITE_SYNC = lvds->lcd_timing.miscinfo & ATOM_COMPOSITESYNC; -    info->lcd_timing.misc_info.INTERLACE =
+    info->lcd_timing.misc_info.INTERLACE = (uint32_t) lvds->lcd_timing.miscinfo & ATOM_INTERLACE;

I wasn't sure offhand, so I had to write a little test program, but it looks like this doesn't work as intended: (lvds->lcd_timing.miscinfo & ATOM_INTERLACE) is an unsigned 16-bit value, which is either 0x80

Quoted 8 lines

(ATOM_INTERLACE) or 0. Assigning that to the unsigned 1-bit field info->lcd_timing.misc_info.INTERLACE always results in 0. Casting the 16-bit value to 32 bits doesn't change that. I think what's intended here is something like info->lcd_timing.misc_info.INTERLACE = (lvds->lcd_timing.miscinfo & ATOM_INTERLACE) != 0; Looks like there's the same problem with other fields of info->lcd_timing.misc_info above. Another possible solution is making the fields of struct misc_info bool instead of uint32_t.

While your approach works as well IIRC converting an arbitrary value into a boolean is usually done with "!!".

Quoted 7 lines
Quoted 4 lines

E.g. that should look like:

    info->lcd_timing.misc_info.INTERLACE = !!(lvds->lcd_timing.miscinfo & ATOM_INTERLACE);

Right, that works as well, thanks.

Thanks, this is really the correct approach.

Harry

Quoted 1 line

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx