drm: Review of mode copies
Subsystems (12)
v2 cover drm: Review of mode copies
From: Ville Syrjälä <[email protected]>
Repost of the stragglers from
https://patchwork.freedesktop.org/series/100393/
Note that I didn't rerun the cocci stuff, nor have I had time to come up with something to inluce the cocci scripts in the tree. So it's possible this is missing some new things that have snuck in the meantime.
Ville Syrjälä (7):
drm/amdgpu: Use drm_mode_init() for on-stack modes drm/hisilicon: Use drm_mode_init() for on-stack modes drm/msm: Use drm_mode_init() for on-stack modes drm/msm: Use drm_mode_copy()
drm/mtk: Use drm_mode_init() for on-stack modes drm/rockchip: Use drm_mode_copy()
drm/sti: Use drm_mode_copy()
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 3 ++- drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c | 2 +- drivers/gpu/drm/mediatek/mtk_hdmi.c | 2 +- drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c | 7 +++++-- drivers/gpu/drm/msm/dp/dp_display.c | 2 +- drivers/gpu/drm/rockchip/cdn-dp-core.c | 2 +- drivers/gpu/drm/rockchip/inno_hdmi.c | 2 +- drivers/gpu/drm/rockchip/rk3066_hdmi.c | 2 +- drivers/gpu/drm/sti/sti_dvo.c | 2 +- drivers/gpu/drm/sti/sti_hda.c | 2 +- drivers/gpu/drm/sti/sti_hdmi.c | 2 +- 11 files changed, 16 insertions(+), 12 deletions(-)
Signature · 1 line
2.37.4
PATCH v2 1/7 drm/amdgpu: Use drm_mode_init() for on-stack modes
From: Ville Syrjälä <[email protected]>
Initialize on-stack modes with drm_mode_init() to guarantee no stack garbage in the list head, or that we aren't copying over another mode's list head.
Based on the following cocci script, with manual fixups:
@decl@
identifier M;
expression E;
@@
- struct drm_display_mode M = E;
+ struct drm_display_mode M;
@@
identifier decl.M;
expression decl.E;
statement S, S1;
@@
struct drm_display_mode M;
... when != S
+ drm_mode_init(&M, &E);
+
S1
@@
expression decl.E;
@@
- &*E
+ E
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2 -1
@@ -5685,7 +5685,7 @@ create_stream_for_sink(struct amdgpu_dm_connector *aconnector,const struct drm_connector_state *con_state = dm_state ? &dm_state->base :NULL ;struct dc_stream_state *stream =NULL ; -struct drm_display_mode mode = *drm_mode; +struct drm_display_mode mode;struct drm_display_mode saved_mode;struct drm_display_mode *freesync_mode =NULL ;bool native_mode_found = false;
@@ -5699,6 +5699,7 @@ create_stream_for_sink(struct amdgpu_dm_connector *aconnector,struct dc_sink *sink =NULL ; +drm_mode_init (&mode, drm_mode);memset (&saved_mode,0 ,sizeof (saved_mode));if (aconnector ==NULL ) {
Signature · 1 line
2.37.4
Alex Deucher
AppliedRe: [PATCH v2 1/7] drm/amdgpu: Use drm_mode_init() for on-stack modes
Quoted 32 lines · Ville Syrjala
From: Ville Syrjälä <[email protected]>
Initialize on-stack modes with
drm_mode_init()to guarantee no stack garbage in the list head, or that we aren't copying over another mode's list head.Based on the following cocci script, with manual fixups:
@decl@
identifier M;
expression E;
@@
- structdrm_display_modeM = E;
+ structdrm_display_modeM;@@
identifier decl.M;
expression decl.E;
statement S, S1;
@@
structdrm_display_modeM;
... when != S
+drm_mode_init(&M, &E);
+
S1@@
expression decl.E;
@@
- &*E
+ E
Quoted 7 lines
Cc Harry Wentland <[email protected]>Cc Leo Li <[email protected]>Cc Rodrigo Siqueira <[email protected]>Cc Alex Deucher <[email protected]>Reviewed-by Harry Wentland <[email protected]>Signed-off-by Ville Syrjälä <[email protected]>
Applied. Thanks!
Alex
Quoted 28 lines
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2
-2@@ -5685,7 +5685,7 @@ create_stream_for_sink(struct amdgpu_dm_connector *aconnector,const struct drm_connector_state *con_state = dm_state ? &dm_state->base :NULL ;struct dc_stream_state *stream =NULL ; -struct drm_display_mode mode = *drm_mode; +struct drm_display_mode mode;struct drm_display_mode saved_mode;struct drm_display_mode *freesync_mode =NULL ;bool native_mode_found = false;@@ -5699,6 +5699,7 @@ create_stream_for_sink(struct amdgpu_dm_connector *aconnector,struct dc_sink *sink =NULL ; +drm_mode_init (&mode, drm_mode);memset (&saved_mode,0 ,sizeof (saved_mode));if (aconnector ==NULL ) { --2.37.4
PATCH v2 2/7 drm/hisilicon: Use drm_mode_init() for on-stack modes
In reply to Ville SyrjalaFrom: Ville Syrjälä <[email protected]>
Initialize on-stack modes with drm_mode_init() to guarantee no stack garbage in the list head.
--- drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c +1 -1
@@ -658,7 +658,7 @@ static enum drm_mode_status dsi_encoder_mode_valid(struct drm_encoder *encoder,* reset adj_mode to the mode value each time, * so we don't adjust the mode twice */ -drm_mode_copy (&adj_mode, mode); +drm_mode_init (&adj_mode, mode); crtc_funcs = crtc->helper_private;if (crtc_funcs && crtc_funcs->mode_fixup)
Signature · 1 line
2.37.4
PATCH v2 3/7 drm/msm: Use drm_mode_init() for on-stack modes
In reply to Ville SyrjalaFrom: Ville Syrjälä <[email protected]>
Initialize on-stack modes with drm_mode_init() to guarantee no stack garbage in the list head, or that we aren't copying over another mode's list head.
Based on the following cocci script, with manual fixups:
@decl@
identifier M;
expression E;
@@
- struct drm_display_mode M = E;
+ struct drm_display_mode M;
@@
identifier decl.M;
expression decl.E;
statement S, S1;
@@
struct drm_display_mode M;
... when != S
+ drm_mode_init(&M, &E);
+
S1
@@
expression decl.E;
@@
- &*E
+ E
--- drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c +5 -2
@@ -237,12 +237,13 @@ static void dpu_encoder_phys_vid_setup_timing_engine(unsigned long lock_flags;struct dpu_hw_intf_cfg intf_cfg = {0 }; +drm_mode_init (&mode, &phys_enc->cached_mode); +if (!phys_enc->hw_ctl->ops.setup_intf_cfg) {DPU_ERROR ("invalid encoder %d\n" , phys_enc !=NULL );return ; } - mode = phys_enc->cached_mode;if (!phys_enc->hw_intf->ops.setup_timing_gen) {DPU_ERROR ("timing engine setup is not supported\n" );return ;
@@ -634,7 +635,9 @@ static int dpu_encoder_phys_vid_get_frame_count( {struct intf_status s = {0 };u32 fetch_start =0 ; -struct drm_display_mode mode = phys_enc->cached_mode; +struct drm_display_mode mode; + +drm_mode_init (&mode, &phys_enc->cached_mode);if (!dpu_encoder_phys_vid_is_master (phys_enc))return -EINVAL ;
Signature · 1 line
2.37.4
PATCH v2 4/7 drm/msm: Use drm_mode_copy()
In reply to Ville SyrjalaFrom: Ville Syrjälä <[email protected]>
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
--- drivers/gpu/drm/msm/dp/dp_display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/msm/dp/dp_display.c +1 -1
@@ -857,7 +857,7 @@ static int dp_display_set_mode(struct msm_dp *dp_display, dp = container_of(dp_display, struct dp_display_private, dp_display); - dp->panel->dp_mode.drm_mode = mode->drm_mode; +drm_mode_copy (&dp->panel->dp_mode.drm_mode, &mode->drm_mode); dp->panel->dp_mode.bpp = mode->bpp; dp->panel->dp_mode.capabilities = mode->capabilities;dp_panel_init_panel_info (dp->panel);
Signature · 1 line
2.37.4
PATCH v2 5/7 drm/mtk: Use drm_mode_init() for on-stack modes
In reply to Ville SyrjalaFrom: Ville Syrjälä <[email protected]>
Initialize on-stack modes with drm_mode_init() to guarantee no stack garbage in the list head.
Based on the following cocci script, with manual fixups:
@decl@
identifier M;
expression E;
@@
- struct drm_display_mode M = E;
+ struct drm_display_mode M;
@@
identifier decl.M;
expression decl.E;
statement S, S1;
@@
struct drm_display_mode M;
... when != S
+ drm_mode_init(&M, &E);
+
S1
@@
expression decl.E;
@@
- &*E
+ E
--- drivers/gpu/drm/mediatek/mtk_hdmi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/mediatek/mtk_hdmi.c +1 -1
@@ -1217,7 +1217,7 @@ static int mtk_hdmi_bridge_mode_valid(struct drm_bridge *bridge,if (next_bridge) {struct drm_display_mode adjusted_mode; -drm_mode_copy (&adjusted_mode, mode); +drm_mode_init (&adjusted_mode, mode);if (!drm_bridge_chain_mode_fixup (next_bridge, mode, &adjusted_mode))return MODE_BAD ;
Signature · 1 line
2.37.4
PATCH v2 6/7 drm/rockchip: Use drm_mode_copy()
In reply to Ville SyrjalaFrom: Ville Syrjälä <[email protected]>
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
--- drivers/gpu/drm/rockchip/cdn-dp-core.c | 2 +- drivers/gpu/drm/rockchip/inno_hdmi.c | 2 +- drivers/gpu/drm/rockchip/rk3066_hdmi.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/rockchip/cdn-dp-core.c +1 -1
@@ -571,7 +571,7 @@ static void cdn_dp_encoder_mode_set(struct drm_encoder *encoder, video->v_sync_polarity = !!(mode->flags &DRM_MODE_FLAG_NVSYNC ); video->h_sync_polarity = !!(mode->flags &DRM_MODE_FLAG_NHSYNC ); -memcpy (&dp->mode, adjusted,sizeof (*mode)); +drm_mode_copy (&dp->mode, adjusted); }static bool cdn_dp_check_link_status (struct cdn_dp_device *dp)
drivers/gpu/drm/rockchip/inno_hdmi.c +1 -1
@@ -499,7 +499,7 @@ static void inno_hdmi_encoder_mode_set(struct drm_encoder *encoder,inno_hdmi_setup (hdmi, adj_mode);/* Store the display mode for plugin/DPMS poweron events */ -memcpy (&hdmi->previous_mode, adj_mode,sizeof (hdmi->previous_mode)); +drm_mode_copy (&hdmi->previous_mode, adj_mode); }static void inno_hdmi_encoder_enable (struct drm_encoder *encoder)
drivers/gpu/drm/rockchip/rk3066_hdmi.c +1 -1
@@ -395,7 +395,7 @@ rk3066_hdmi_encoder_mode_set(struct drm_encoder *encoder,struct rk3066_hdmi *hdmi =encoder_to_rk3066_hdmi (encoder);/* Store the display mode for plugin/DPMS poweron events. */ -memcpy (&hdmi->previous_mode, adj_mode,sizeof (hdmi->previous_mode)); +drm_mode_copy (&hdmi->previous_mode, adj_mode); }static void rk3066_hdmi_encoder_enable (struct drm_encoder *encoder)
Signature · 1 line
2.37.4
PATCH v2 7/7 drm/sti: Use drm_mode_copy()
In reply to Ville SyrjalaFrom: Ville Syrjälä <[email protected]>
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
--- drivers/gpu/drm/sti/sti_dvo.c | 2 +- drivers/gpu/drm/sti/sti_hda.c | 2 +- drivers/gpu/drm/sti/sti_hdmi.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/sti/sti_dvo.c +1 -1
@@ -288,7 +288,7 @@ static void sti_dvo_set_mode(struct drm_bridge *bridge,DRM_DEBUG_DRIVER ("\n" ); -memcpy (&dvo->mode, mode,sizeof (struct drm_display_mode )); +drm_mode_copy (&dvo->mode, mode);/* According to the path used (main or aux), the dvo clocks should * have a different parent clock. */
drivers/gpu/drm/sti/sti_hda.c +1 -1
@@ -524,7 +524,7 @@ static void sti_hda_set_mode(struct drm_bridge *bridge,DRM_DEBUG_DRIVER ("\n" ); -memcpy (&hda->mode, mode,sizeof (struct drm_display_mode )); +drm_mode_copy (&hda->mode, mode);if (!hda_get_mode_idx (hda->mode, &mode_idx)) {DRM_ERROR ("Undefined mode\n" );
drivers/gpu/drm/sti/sti_hdmi.c +1 -1
@@ -941,7 +941,7 @@ static void sti_hdmi_set_mode(struct drm_bridge *bridge,DRM_DEBUG_DRIVER ("\n" );/* Copy the drm display mode in the connector local structure */ -memcpy (&hdmi->mode, mode,sizeof (struct drm_display_mode )); +drm_mode_copy (&hdmi->mode, mode);/* Update clock framerate according to the selected mode */ ret =clk_set_rate (hdmi->clk_pix, mode->clock *1000 );
Signature · 1 line
2.37.4
Quoted 10 lines · Ville Syrjala
From: Ville Syrjälä <[email protected]>
Repost of the stragglers from
https://patchwork.freedesktop.org/series/100393/Note that I didn't rerun the cocci stuff, nor have I had time to come up with something to inluce the cocci scripts in the tree. So it's possible this is missing some new things that have snuck in the meantime.
Quoted 8 lines
Ville Syrjälä (7):
drm/amdgpu: Usedrm_mode_init()for on-stack modes drm/hisilicon: Usedrm_mode_init()for on-stack modes drm/msm: Usedrm_mode_init()for on-stack modes drm/msm: Usedrm_mode_copy()
drm/mtk: Usedrm_mode_init()for on-stack modes drm/rockchip: Usedrm_mode_copy()
drm/sti: Usedrm_mode_copy()
On the series:
Imo ping Alex/Rob and stuff everything left into drm-misc-next. -Daniel
Quoted 17 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 3 ++- drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c | 2 +- drivers/gpu/drm/mediatek/mtk_hdmi.c | 2 +- drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c | 7 +++++-- drivers/gpu/drm/msm/dp/dp_display.c | 2 +- drivers/gpu/drm/rockchip/cdn-dp-core.c | 2 +- drivers/gpu/drm/rockchip/inno_hdmi.c | 2 +- drivers/gpu/drm/rockchip/rk3066_hdmi.c | 2 +- drivers/gpu/drm/sti/sti_dvo.c | 2 +- drivers/gpu/drm/sti/sti_hda.c | 2 +- drivers/gpu/drm/sti/sti_hdmi.c | 2 +- 11 files changed, 16 insertions(+), 12 deletions(-)Signature · 1 line
2.37.4
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Alex Deucher
Acked-byQuoted 21 lines · Daniel Vetter
Quoted 10 lines · Ville Syrjala
From: Ville Syrjälä <[email protected]>
Repost of the stragglers from
https://patchwork.freedesktop.org/series/100393/Note that I didn't rerun the cocci stuff, nor have I had time to come up with something to inluce the cocci scripts in the tree. So it's possible this is missing some new things that have snuck in the meantime.
Quoted 8 lines
Ville Syrjälä (7):
drm/amdgpu: Usedrm_mode_init()for on-stack modes drm/hisilicon: Usedrm_mode_init()for on-stack modes drm/msm: Usedrm_mode_init()for on-stack modes drm/msm: Usedrm_mode_copy()
drm/mtk: Usedrm_mode_init()for on-stack modes drm/rockchip: Usedrm_mode_copy()
drm/sti: Usedrm_mode_copy()
Quoted 5 lines
On the series:
Reviewed-by Daniel Vetter <[email protected]>Imo ping Alex/Rob and stuff everything left into drm-misc-next.
Feel free to take this series through whatever tree makes sense. If you want me to pick up the amdgpu change directly, I can do that too.
Alex
Quoted 24 lines
-Daniel
Quoted 14 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 3 ++- drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c | 2 +- drivers/gpu/drm/mediatek/mtk_hdmi.c | 2 +- drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c | 7 +++++-- drivers/gpu/drm/msm/dp/dp_display.c | 2 +- drivers/gpu/drm/rockchip/cdn-dp-core.c | 2 +- drivers/gpu/drm/rockchip/inno_hdmi.c | 2 +- drivers/gpu/drm/rockchip/rk3066_hdmi.c | 2 +- drivers/gpu/drm/sti/sti_dvo.c | 2 +- drivers/gpu/drm/sti/sti_hda.c | 2 +- drivers/gpu/drm/sti/sti_hdmi.c | 2 +- 11 files changed, 16 insertions(+), 12 deletions(-)Quoted 3 lines
--
2.37.4--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Quoted 24 lines · Alex Deucher
Quoted 23 lines · Daniel Vetter
Quoted 10 lines · Ville Syrjala
From: Ville Syrjälä <[email protected]>
Repost of the stragglers from
https://patchwork.freedesktop.org/series/100393/Note that I didn't rerun the cocci stuff, nor have I had time to come up with something to inluce the cocci scripts in the tree. So it's possible this is missing some new things that have snuck in the meantime.
Quoted 8 lines
Ville Syrjälä (7):
drm/amdgpu: Usedrm_mode_init()for on-stack modes drm/hisilicon: Usedrm_mode_init()for on-stack modes drm/msm: Usedrm_mode_init()for on-stack modes drm/msm: Usedrm_mode_copy()
drm/mtk: Usedrm_mode_init()for on-stack modes drm/rockchip: Usedrm_mode_copy()
drm/sti: Usedrm_mode_copy()On the series:
Quoted 7 lines
Quoted 3 lines
Reviewed-by Daniel Vetter <[email protected]>Imo ping Alex/Rob and stuff everything left into drm-misc-next.
Acked-by Alex Deucher <[email protected]>Feel free to take this series through whatever tree makes sense. If you want me to pick up the amdgpu change directly, I can do that too.
Please do. Less work for me ;)
Signature · 2 lines
Ville Syrjälä Intel