Skip to content

Commit 606d587

Browse files
vsyrjalaalexdeucher
authored andcommitted
drm/radeon: Use drm_mode_copy()
struct drm_display_mode embeds a list head, so overwriting the full struct with another one will corrupt the list (if the destination mode is on a list). Use drm_mode_copy() instead which explicitly preserves the list head of the destination mode. Even if we know the destination mode is not on any list using drm_mode_copy() seems decent as it sets a good example. Bad examples of not using it might eventually get copied into code where preserving the list head actually matters. Obviously one case not covered here is when the mode itself is embedded in a larger structure and the whole structure is copied. But if we are careful when copying into modes embedded in structures I think we can be a little more reassured that bogus list heads haven't been propagated in. @is_mode_copy@ @@ drm_mode_copy(...) { ... } @Depends on !is_mode_copy@ struct drm_display_mode *mode; expression E, S; @@ ( - *mode = E + drm_mode_copy(mode, &E) | - memcpy(mode, E, S) + drm_mode_copy(mode, E) ) @Depends on !is_mode_copy@ struct drm_display_mode mode; expression E; @@ ( - mode = E + drm_mode_copy(&mode, &E) | - memcpy(&mode, E, S) + drm_mode_copy(&mode, E) ) @@ struct drm_display_mode *mode; @@ - &*mode + mode Cc: Alex Deucher <[email protected]> Cc: [email protected] Signed-off-by: Ville Syrjälä <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 07d0146 commit 606d587

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/gpu/drm/radeon/radeon_connectors.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
777777
if (mode->type & DRM_MODE_TYPE_PREFERRED) {
778778
if (mode->hdisplay != native_mode->hdisplay ||
779779
mode->vdisplay != native_mode->vdisplay)
780-
memcpy(native_mode, mode, sizeof(*mode));
780+
drm_mode_copy(native_mode, mode);
781781
}
782782
}
783783

@@ -786,7 +786,7 @@ static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
786786
list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
787787
if (mode->hdisplay == native_mode->hdisplay &&
788788
mode->vdisplay == native_mode->vdisplay) {
789-
*native_mode = *mode;
789+
drm_mode_copy(native_mode, mode);
790790
drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
791791
DRM_DEBUG_KMS("Determined LVDS native mode details from EDID\n");
792792
break;

0 commit comments

Comments
 (0)