drm: writeback: clean up writeback connector initialization
Subsystems (11)
v3 cover drm: writeback: clean up writeback connector initialization
Drivers using drm_writeback_connector_init() / _with_encoder() don't perform cleanup in a manner similar to drmm_writeback_connector_init() (see drm_writeback_connector_cleanup()). Migrate all existing drivers to use drmm_writeback_connector_init(), drop drm_writeback_connector_init() and drm_writeback_connector::encoder (it's unused afterwards).
This series leaves former drm_writeback_connector_init_with_encoder() (renamed to drm_writeback_connector_init as a non-managed counterpart for drmm_writeback_connector_init()). It is supposed to be used by drivers which can not use drmm functions (like Intel). However I think it would be better to drop it completely.
---
Changes in v3:
- Fixed subject prefix for the rcar-du patch (Jessica Zhang)
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Switched to drm_crtc_mask() where applicable (Louis Chauvet)
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Dmitry Baryshkov (8):
drm/amd/display: use drmm_writeback_connector_init() drm/komeda: use drmm_writeback_connector_init() drm/mali: use drmm_writeback_connector_init() drm/msm/dpu: use drmm_writeback_connector_init()
drm: renesas: rcar-du: use drmm_writeback_connector_init() drm/vc4: use drmm_writeback_connector_init()
drm: writeback: drop excess connector initialization functions
drm: writeback: rename drm_writeback_connector_init_with_encoder()
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_wb.c | 18 ++++-- .../drm/arm/display/komeda/komeda_wb_connector.c | 30 ++++++---- drivers/gpu/drm/arm/malidp_mw.c | 25 ++++---- drivers/gpu/drm/drm_writeback.c | 69 +++------------------- drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c | 10 +--- .../gpu/drm/renesas/rcar-du/rcar_du_writeback.c | 23 +++++--- drivers/gpu/drm/vc4/vc4_txp.c | 9 ++- include/drm/drm_writeback.h | 22 +------ 9 files changed, 77 insertions(+), 131 deletions(-)
---
base-commit: c8cea4371e5eca30cda8660aabb337747dabc51d
change-id: 20250801-wb-drop-encoder-97a0c75bd5d7
Best regards,
Signature · 2 lines
With best wishes Dmitry
PATCH v3 1/8 drm/amd/display: use drmm_writeback_connector_init()
Use drmm_plain_encoder_alloc() to allocate simple encoder and drmm_writeback_connector_init() in order to initialize writeback connector instance.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_wb.c | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -1
@@ -10006,7 +10006,7 @@ static void dm_set_writeback(struct amdgpu_display_manager *dm,return ; } - acrtc =to_amdgpu_crtc (wb_conn->encoder.crtc); + acrtc =to_amdgpu_crtc (crtc_state->base.crtc);if (!acrtc) {drm_err (adev_to_drm (adev),"no amdgpu_crtc found\n" );kfree (wb_info);
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_wb.c +13 -5
@@ -171,7 +171,6 @@ static const struct drm_encoder_helper_funcs amdgpu_dm_wb_encoder_helper_funcs =static const struct drm_connector_funcs amdgpu_dm_wb_connector_funcs = { .fill_modes = drm_helper_probe_single_connector_modes, - .destroy = drm_connector_cleanup, .reset = amdgpu_dm_connector_funcs_reset, .atomic_duplicate_state = amdgpu_dm_connector_atomic_duplicate_state, .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
@@ -190,17 +189,26 @@ int amdgpu_dm_wb_connector_init(struct amdgpu_display_manager *dm,struct dc *dc = dm->dc;struct dc_link *link =dc_get_link_at_index (dc, link_index);int res =0 ; +struct drm_encoder *encoder; + + encoder =drmm_plain_encoder_alloc (&dm->adev->ddev,NULL , +DRM_MODE_ENCODER_VIRTUAL ,NULL ); +if (IS_ERR (encoder)) +return PTR_ERR (encoder); + +drm_encoder_helper_add (encoder, &amdgpu_dm_wb_encoder_helper_funcs); + + encoder->possible_crtcs =amdgpu_dm_get_encoder_crtc_mask (dm->adev); wbcon->link = link;drm_connector_helper_add (&wbcon->base.base, &amdgpu_dm_wb_conn_helper_funcs); - res =drm_writeback_connector_init (&dm->adev->ddev, &wbcon->base, + res =drmm_writeback_connector_init (&dm->adev->ddev, &wbcon->base, &amdgpu_dm_wb_connector_funcs, - &amdgpu_dm_wb_encoder_helper_funcs, + encoder, amdgpu_dm_wb_formats, -ARRAY_SIZE (amdgpu_dm_wb_formats), -amdgpu_dm_get_encoder_crtc_mask (dm->adev)); +ARRAY_SIZE (amdgpu_dm_wb_formats));if (res)return res;
Signature · 1 line
2.47.2
PATCH v3 2/8 drm/komeda: use drmm_writeback_connector_init()
In reply to Dmitry BaryshkovUse drmm_plain_encoder_alloc() to allocate simple encoder and drmm_writeback_connector_init() in order to initialize writeback connector instance.
--- .../drm/arm/display/komeda/komeda_wb_connector.c | 30 ++++++++++++---------- 1 file changed, 17 insertions(+), 13 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_wb_connector.c +17 -13
@@ -5,6 +5,7 @@* */ #include <drm/drm_framebuffer.h> +#include <drm/drm_managed.h> #include "komeda_dev.h" #include "komeda_kms.h"
@@ -121,17 +122,10 @@ komeda_wb_connector_fill_modes(struct drm_connector *connector,return 0 ; } -static void komeda_wb_connector_destroy (struct drm_connector *connector) -{ -drm_connector_cleanup (connector); -kfree (to_kconn (to_wb_conn (connector))); -} -static const struct drm_connector_funcs komeda_wb_connector_funcs = { .reset = drm_atomic_helper_connector_reset, .detect = komeda_wb_connector_detect, .fill_modes = komeda_wb_connector_fill_modes, - .destroy = komeda_wb_connector_destroy, .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, };
@@ -143,13 +137,15 @@ static int komeda_wb_connector_add(struct komeda_kms_dev *kms,struct komeda_wb_connector *kwb_conn;struct drm_writeback_connector *wb_conn;struct drm_display_info *info; +struct drm_encoder *encoder; +u32 *formats, n_formats =0 ;int err;if (!kcrtc->master->wb_layer)return 0 ; - kwb_conn =kzalloc (sizeof (*kwb_conn),GFP_KERNEL ); + kwb_conn =drmm_kzalloc (&kms->base,sizeof (*kwb_conn),GFP_KERNEL );if (!kwb_conn)return -ENOMEM ;
@@ -165,11 +161,19 @@ static int komeda_wb_connector_add(struct komeda_kms_dev *kms,return -ENOMEM ; } - err =drm_writeback_connector_init (&kms->base, wb_conn, - &komeda_wb_connector_funcs, - &komeda_wb_encoder_helper_funcs, - formats, n_formats, -BIT (drm_crtc_index (&kcrtc->base))); + encoder =drmm_plain_encoder_alloc (&kms->base,NULL , +DRM_MODE_ENCODER_VIRTUAL ,NULL ); +if (IS_ERR (encoder)) +return PTR_ERR (encoder); + +drm_encoder_helper_add (encoder, &komeda_wb_encoder_helper_funcs); + + encoder->possible_crtcs =drm_crtc_mask (&kcrtc->base); + + err =drmm_writeback_connector_init (&kms->base, wb_conn, + &komeda_wb_connector_funcs, + encoder, + formats, n_formats);komeda_put_fourcc_list (formats);if (err) {kfree (kwb_conn);
Signature · 1 line
2.47.2
PATCH v3 3/8 drm/mali: use drmm_writeback_connector_init()
In reply to Dmitry BaryshkovUse drmm_plain_encoder_alloc() to allocate simple encoder and drmm_writeback_connector_init() in order to initialize writeback connector instance.
--- drivers/gpu/drm/arm/malidp_mw.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
drivers/gpu/drm/arm/malidp_mw.c +14 -11
@@ -84,11 +84,6 @@ malidp_mw_connector_detect(struct drm_connector *connector, bool force)return connector_status_connected; } -static void malidp_mw_connector_destroy (struct drm_connector *connector) -{ -drm_connector_cleanup (connector); -} -static struct drm_connector_state *malidp_mw_connector_duplicate_state (struct drm_connector *connector) {
@@ -114,7 +109,6 @@ static const struct drm_connector_funcs malidp_mw_connector_funcs = { .reset = malidp_mw_connector_reset, .detect = malidp_mw_connector_detect, .fill_modes = drm_helper_probe_single_connector_modes, - .destroy = malidp_mw_connector_destroy, .atomic_duplicate_state = malidp_mw_connector_duplicate_state, .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, };
@@ -211,6 +205,7 @@ static u32 *get_writeback_formats(struct malidp_drm *malidp, int *n_formats)int malidp_mw_connector_init (struct drm_device *drm) {struct malidp_drm *malidp =drm_to_malidp (drm); +struct drm_encoder *encoder;u32 *formats;int ret, n_formats;
@@ -224,11 +219,19 @@ int malidp_mw_connector_init(struct drm_device *drm)if (!formats)return -ENOMEM ; - ret =drm_writeback_connector_init (drm, &malidp->mw_connector, - &malidp_mw_connector_funcs, - &malidp_mw_encoder_helper_funcs, - formats, n_formats, -1 <<drm_crtc_index (&malidp->crtc)); + encoder =drmm_plain_encoder_alloc (drm,NULL ,DRM_MODE_ENCODER_VIRTUAL , +NULL ); +if (IS_ERR (encoder)) +return PTR_ERR (encoder); + +drm_encoder_helper_add (encoder, &malidp_mw_encoder_helper_funcs); + + encoder->possible_crtcs =drm_crtc_mask (&malidp->crtc); + + ret =drmm_writeback_connector_init (drm, &malidp->mw_connector, + &malidp_mw_connector_funcs, + encoder, + formats, n_formats);kfree (formats);if (ret)return ret;
Signature · 1 line
2.47.2
PATCH v3 4/8 drm/msm/dpu: use drmm_writeback_connector_init()
In reply to Dmitry BaryshkovUse drmm_plain_encoder_alloc() to allocate simple encoder and drmm_writeback_connector_init() in order to initialize writeback connector instance.
--- drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c +3 -7
@@ -80,7 +80,6 @@ static int dpu_wb_conn_atomic_check(struct drm_connector *connector,static const struct drm_connector_funcs dpu_wb_conn_funcs = { .reset = drm_atomic_helper_connector_reset, .fill_modes = drm_helper_probe_single_connector_modes, - .destroy = drm_connector_cleanup, .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, };
@@ -131,12 +130,9 @@ int dpu_writeback_init(struct drm_device *dev, struct drm_encoder *enc,drm_connector_helper_add (&dpu_wb_conn->base.base, &dpu_wb_conn_helper_funcs); -/* DPU initializes the encoder and sets it up completely for writeback -* cases and hence should use the new API drm_writeback_connector_init_with_encoder -* to initialize the writeback connector -*/ - rc =drm_writeback_connector_init_with_encoder (dev, &dpu_wb_conn->base, enc, - &dpu_wb_conn_funcs, format_list, num_formats); + rc =drmm_writeback_connector_init (dev, &dpu_wb_conn->base, + &dpu_wb_conn_funcs, enc, + format_list, num_formats);if (!rc) dpu_wb_conn->wb_enc = enc;
Signature · 1 line
2.47.2
Re: [PATCH v3 4/8] drm/msm/dpu: use drmm_writeback_connector_init()
Le 19/08/2025 à 22:32, Dmitry Baryshkov a écrit :
Quoted 31 lines
Use
drmm_plain_encoder_alloc()to allocate simple encoder anddrmm_writeback_connector_init()in order to initialize writeback connector instance.Reviewed-by Louis Chauvet <[email protected]>Reviewed-by Suraj Kandpal <[email protected]>Reviewed-by Jessica Zhang <[email protected]>Signed-off-by Dmitry Baryshkov <[email protected]>--- drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c +0
-3@@ -80,7 +80,6 @@ static int dpu_wb_conn_atomic_check(struct drm_connector *connector,static const struct drm_connector_funcs dpu_wb_conn_funcs = { .reset = drm_atomic_helper_connector_reset, .fill_modes = drm_helper_probe_single_connector_modes, - .destroy = drm_connector_cleanup, .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, };@@ -131,12 +130,9 @@ int dpu_writeback_init(struct drm_device *dev, struct drm_encoder *enc,drm_connector_helper_add (&dpu_wb_conn->base.base, &dpu_wb_conn_helper_funcs); -/* DPU initializes the encoder and sets it up completely for writeback -* cases and hence should use the new API drm_writeback_connector_init_with_encoder
drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c int dpu_writeback_init(struct drm_device *dev, struct drm_encoder *enc, · line 138
Quoted 10 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c +3
-4-* to initialize the writeback connector -*/ - rc =drm_writeback_connector_init_with_encoder (dev, &dpu_wb_conn->base, enc, - &dpu_wb_conn_funcs, format_list, num_formats); + rc =drmm_writeback_connector_init (dev, &dpu_wb_conn->base, + &dpu_wb_conn_funcs, enc, + format_list, num_formats);if (!rc) dpu_wb_conn->wb_enc = enc;
dpu_wb_conn is allocated a few lines above using devm_kzalloc().
Based on [1], mixing devm_ and drmm_ is not safe and can lead to a uaf.
Is it correct here?
If the explanation at [1] is correct, then &dpu_wb_conn->base would point to some released memory, IIUC.
just my 2c.
CJ
Re: [PATCH v3 4/8] drm/msm/dpu: use drmm_writeback_connector_init()
Quoted 33 lines · Christophe JAILLET
Le 19/08/2025 à 22:32, Dmitry Baryshkov a écrit :
Quoted 32 lines
Use
drmm_plain_encoder_alloc()to allocate simple encoder anddrmm_writeback_connector_init()in order to initialize writeback connector instance.Reviewed-by Louis Chauvet <[email protected]>Reviewed-by Suraj Kandpal <[email protected]>Reviewed-by Jessica Zhang <[email protected]>Signed-off-by Dmitry Baryshkov <[email protected]>--- drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c +0
-7@@ -80,7 +80,6 @@ static int dpu_wb_conn_atomic_check(struct drm_connector *connector,static const struct drm_connector_funcs dpu_wb_conn_funcs = { .reset = drm_atomic_helper_connector_reset, .fill_modes = drm_helper_probe_single_connector_modes, - .destroy = drm_connector_cleanup, .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, };@@ -131,12 +130,9 @@ int dpu_writeback_init(struct drm_device *dev, struct drm_encoder *enc,drm_connector_helper_add (&dpu_wb_conn->base.base, &dpu_wb_conn_helper_funcs); -/* DPU initializes the encoder and sets it up completely for writeback -* cases and hence should use the new API drm_writeback_connector_init_with_encoder -* to initialize the writeback connector -*/ - rc =drm_writeback_connector_init_with_encoder (dev, &dpu_wb_conn->base, enc, - &dpu_wb_conn_funcs, format_list, num_formats);
Quoted 8 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c int dpu_writeback_init(struct drm_device *dev, struct drm_encoder *enc,
Quoted 6 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c +3
-0+ rc =drmm_writeback_connector_init (dev, &dpu_wb_conn->base, + &dpu_wb_conn_funcs, enc, + format_list, num_formats);if (!rc) dpu_wb_conn->wb_enc = enc;
dpu_wb_connis allocated a few lines above usingdevm_kzalloc().
That's a valid point, thanks!
Quoted 13 lines
Based on [1], mixing
devm_anddrmm_is not safe and can lead to a uaf.Is it correct here?
If the explanation at [1] is correct, then&dpu_wb_conn->basewould point to some released memory, IIUC.just my 2c.
CJ
Signature · 2 lines
With best wishes Dmitry
Re: [PATCH v3 4/8] drm/msm/dpu: use drmm_writeback_connector_init()
Le 08/09/2025 à 23:26, Dmitry Baryshkov a écrit :
Quoted 43 lines · Christophe JAILLET
Quoted 33 lines
Le 19/08/2025 à 22:32, Dmitry Baryshkov a écrit :
Quoted 32 lines
Use
drmm_plain_encoder_alloc()to allocate simple encoder anddrmm_writeback_connector_init()in order to initialize writeback connector instance.Reviewed-by Louis Chauvet <louis.chauvet-LDxbnhwyfcJBDgjK7y7TUQ-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org>Reviewed-by Suraj Kandpal <suraj.kandpal-ral2JQCrhuEAvxtiuMwx3w-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org>--- drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c +0
-7@@ -80,7 +80,6 @@ static int dpu_wb_conn_atomic_check(struct drm_connector *connector,static const struct drm_connector_funcs dpu_wb_conn_funcs = { .reset = drm_atomic_helper_connector_reset, .fill_modes = drm_helper_probe_single_connector_modes, - .destroy = drm_connector_cleanup, .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, };@@ -131,12 +130,9 @@ int dpu_writeback_init(struct drm_device *dev, struct drm_encoder *enc,drm_connector_helper_add (&dpu_wb_conn->base.base, &dpu_wb_conn_helper_funcs); -/* DPU initializes the encoder and sets it up completely for writeback -* cases and hence should use the new API drm_writeback_connector_init_with_encoder -* to initialize the writeback connector -*/ - rc =drm_writeback_connector_init_with_encoder (dev, &dpu_wb_conn->base, enc, - &dpu_wb_conn_funcs, format_list, num_formats);Quoted 8 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c int dpu_writeback_init(struct drm_device *dev, struct drm_encoder *enc,
Quoted 6 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c +3
-0+ rc =drmm_writeback_connector_init (dev, &dpu_wb_conn->base, + &dpu_wb_conn_funcs, enc, + format_list, num_formats);if (!rc) dpu_wb_conn->wb_enc = enc;
dpu_wb_connis allocated a few lines above usingdevm_kzalloc().
Quoted 1 line
That's a valid point, thanks!
I've not analyzed in details all the patches of the serie, but at least patch 2/8 and 6/8 seems to have the same pattern.
CJ
Quoted 15 lines
Quoted 14 lines
Based on [1], mixing
devm_anddrmm_is not safe and can lead to a uaf.Is it correct here?
If the explanation at [1] is correct, then&dpu_wb_conn->basewould point to some released memory, IIUC.just my 2c.
CJ
Re: [PATCH v3 4/8] drm/msm/dpu: use drmm_writeback_connector_init()
Quoted 44 lines · Christophe JAILLET
Le 08/09/2025 à 23:26, Dmitry Baryshkov a écrit :
Quoted 43 lines · Christophe JAILLET
Quoted 41 lines
Le 19/08/2025 à 22:32, Dmitry Baryshkov a écrit :
Quoted 28 lines
Use
drmm_plain_encoder_alloc()to allocate simple encoder anddrmm_writeback_connector_init()in order to initialize writeback connector instance.Reviewed-by Louis Chauvet <louis.chauvet-LDxbnhwyfcJBDgjK7y7TUQ-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org>Reviewed-by Suraj Kandpal <suraj.kandpal-ral2JQCrhuEAvxtiuMwx3w-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org>--- drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c +0
-3@@ -80,7 +80,6 @@ static int dpu_wb_conn_atomic_check(struct drm_connector *connector,static const struct drm_connector_funcs dpu_wb_conn_funcs = { .reset = drm_atomic_helper_connector_reset, .fill_modes = drm_helper_probe_single_connector_modes, - .destroy = drm_connector_cleanup, .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, };@@ -131,12 +130,9 @@ int dpu_writeback_init(struct drm_device *dev, struct drm_encoder *enc,drm_connector_helper_add (&dpu_wb_conn->base.base, &dpu_wb_conn_helper_funcs); -/* DPU initializes the encoder and sets it up completely for writeback -* cases and hence should use the new API drm_writeback_connector_init_with_encoder drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c int dpu_writeback_init(struct drm_device *dev, struct drm_encoder *enc, · line 136
Quoted 10 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c +3
-4-* to initialize the writeback connector -*/ - rc =drm_writeback_connector_init_with_encoder (dev, &dpu_wb_conn->base, enc, - &dpu_wb_conn_funcs, format_list, num_formats); + rc =drmm_writeback_connector_init (dev, &dpu_wb_conn->base, + &dpu_wb_conn_funcs, enc, + format_list, num_formats);if (!rc) dpu_wb_conn->wb_enc = enc;
dpu_wb_connis allocated a few lines above usingdevm_kzalloc().
Quoted 4 lines
Quoted 1 line
That's a valid point, thanks!
I've not analyzed in details all the patches of the serie, but at least patch 2/8 and 6/8 seems to have the same pattern.
Not quite, 2/8 and 6/8 use drmm_kzalloc(), it is fine to be used with drmm_writeback_connector_init(). This one is indeed incorrect.
Quoted 19 lines
CJ
Quoted 15 lines
Quoted 14 lines
Based on [1], mixing
devm_anddrmm_is not safe and can lead to a uaf.Is it correct here?
If the explanation at [1] is correct, then&dpu_wb_conn->basewould point to some released memory, IIUC.just my 2c.
CJ
Signature · 2 lines
With best wishes Dmitry
Re: [PATCH v3 4/8] drm/msm/dpu: use drmm_writeback_connector_init()
Le 10/09/2025 à 05:47, Dmitry Baryshkov a écrit :
Quoted 45 lines · Christophe JAILLET
Quoted 44 lines
Le 08/09/2025 à 23:26, Dmitry Baryshkov a écrit :
Quoted 43 lines · Christophe JAILLET
Quoted 41 lines
Le 19/08/2025 à 22:32, Dmitry Baryshkov a écrit :
Quoted 28 lines
Use
drmm_plain_encoder_alloc()to allocate simple encoder anddrmm_writeback_connector_init()in order to initialize writeback connector instance.--- drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c +0
-3@@ -80,7 +80,6 @@ static int dpu_wb_conn_atomic_check(struct drm_connector *connector,static const struct drm_connector_funcs dpu_wb_conn_funcs = { .reset = drm_atomic_helper_connector_reset, .fill_modes = drm_helper_probe_single_connector_modes, - .destroy = drm_connector_cleanup, .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, };@@ -131,12 +130,9 @@ int dpu_writeback_init(struct drm_device *dev, struct drm_encoder *enc,drm_connector_helper_add (&dpu_wb_conn->base.base, &dpu_wb_conn_helper_funcs); -/* DPU initializes the encoder and sets it up completely for writeback -* cases and hence should use the new API drm_writeback_connector_init_with_encoder drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c int dpu_writeback_init(struct drm_device *dev, struct drm_encoder *enc, · line 136
Quoted 10 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c +3
-4-* to initialize the writeback connector -*/ - rc =drm_writeback_connector_init_with_encoder (dev, &dpu_wb_conn->base, enc, - &dpu_wb_conn_funcs, format_list, num_formats); + rc =drmm_writeback_connector_init (dev, &dpu_wb_conn->base, + &dpu_wb_conn_funcs, enc, + format_list, num_formats);if (!rc) dpu_wb_conn->wb_enc = enc;
dpu_wb_connis allocated a few lines above usingdevm_kzalloc().
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
That's a valid point, thanks!
I've not analyzed in details all the patches of the serie, but at least patch 2/8 and 6/8 seems to have the same pattern.
Not quite, 2/8 and 6/8 use
drmm_kzalloc(), it is fine to be used withdrmm_writeback_connector_init(). This one is indeed incorrect.
Hmm, for patch 2/8, I looked at the source, not what was changes by your patch... Sorry. :(
For 6/8, I agree with you.
For patch 1/8, I think there is a issue too, becasue of [1], IIUC.
CJ
Quoted 20 lines
Quoted 19 lines
CJ
Quoted 15 lines
Quoted 14 lines
Based on [1], mixing
devm_anddrmm_is not safe and can lead to a uaf.Is it correct here?
If the explanation at [1] is correct, then&dpu_wb_conn->basewould point to some released memory, IIUC.just my 2c.
CJ
Re: [PATCH v3 4/8] drm/msm/dpu: use drmm_writeback_connector_init()
Quoted 55 lines · Christophe JAILLET
Le 10/09/2025 à 05:47, Dmitry Baryshkov a écrit :
Quoted 45 lines · Christophe JAILLET
Quoted 44 lines
Le 08/09/2025 à 23:26, Dmitry Baryshkov a écrit :
Quoted 43 lines · Christophe JAILLET
Quoted 41 lines
Le 19/08/2025 à 22:32, Dmitry Baryshkov a écrit :
Quoted 28 lines
Use
drmm_plain_encoder_alloc()to allocate simple encoder anddrmm_writeback_connector_init()in order to initialize writeback connector instance.--- drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c +0
-3@@ -80,7 +80,6 @@ static int dpu_wb_conn_atomic_check(struct drm_connector *connector,static const struct drm_connector_funcs dpu_wb_conn_funcs = { .reset = drm_atomic_helper_connector_reset, .fill_modes = drm_helper_probe_single_connector_modes, - .destroy = drm_connector_cleanup, .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, };@@ -131,12 +130,9 @@ int dpu_writeback_init(struct drm_device *dev, struct drm_encoder *enc,drm_connector_helper_add (&dpu_wb_conn->base.base, &dpu_wb_conn_helper_funcs); -/* DPU initializes the encoder and sets it up completely for writeback -* cases and hence should use the new API drm_writeback_connector_init_with_encoder drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c int dpu_writeback_init(struct drm_device *dev, struct drm_encoder *enc, · line 136
Quoted 10 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c +3
-4-* to initialize the writeback connector -*/ - rc =drm_writeback_connector_init_with_encoder (dev, &dpu_wb_conn->base, enc, - &dpu_wb_conn_funcs, format_list, num_formats); + rc =drmm_writeback_connector_init (dev, &dpu_wb_conn->base, + &dpu_wb_conn_funcs, enc, + format_list, num_formats);if (!rc) dpu_wb_conn->wb_enc = enc;
dpu_wb_connis allocated a few lines above usingdevm_kzalloc().Quoted 8 lines
Quoted 4 lines
Quoted 1 line
That's a valid point, thanks!
I've not analyzed in details all the patches of the serie, but at least patch 2/8 and 6/8 seems to have the same pattern.
Not quite, 2/8 and 6/8 use
drmm_kzalloc(), it is fine to be used withdrmm_writeback_connector_init(). This one is indeed incorrect.
Quoted 6 lines
Hmm, for patch 2/8, I looked at the source, not what was changes by your patch... Sorry. :(
For 6/8, I agree with you.
For patch 1/8, I think there is a issue too, becasue of [1], IIUC.
There is a different issue then. It's a memory leak inside the AMD driver (since the memory for WB connector will not be kfree()'d by anything).
Quoted 27 lines
CJ
Quoted 20 lines
Quoted 19 lines
CJ
Quoted 15 lines
Quoted 14 lines
Based on [1], mixing
devm_anddrmm_is not safe and can lead to a uaf.Is it correct here?
If the explanation at [1] is correct, then&dpu_wb_conn->basewould point to some released memory, IIUC.just my 2c.
CJ
Signature · 2 lines
With best wishes Dmitry
PATCH v3 5/8 drm: renesas: rcar-du: use drmm_writeback_connector_init()
In reply to Dmitry BaryshkovUse drmm_plain_encoder_alloc() to allocate simple encoder and drmm_writeback_connector_init() in order to initialize writeback connector instance.
--- .../gpu/drm/renesas/rcar-du/rcar_du_writeback.c | 23 +++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
drivers/gpu/drm/renesas/rcar-du/rcar_du_writeback.c +16 -7
@@ -134,7 +134,6 @@ static void rcar_du_wb_conn_reset(struct drm_connector *connector)static const struct drm_connector_funcs rcar_du_wb_conn_funcs = { .reset = rcar_du_wb_conn_reset, .fill_modes = drm_helper_probe_single_connector_modes, - .destroy = drm_connector_cleanup, .atomic_duplicate_state = rcar_du_wb_conn_duplicate_state, .atomic_destroy_state = rcar_du_wb_conn_destroy_state, };
@@ -202,15 +201,25 @@ int rcar_du_writeback_init(struct rcar_du_device *rcdu, {struct drm_writeback_connector *wb_conn = &rcrtc->writeback; +struct drm_encoder *encoder; + + encoder =drmm_plain_encoder_alloc (&rcdu->ddev,NULL , +DRM_MODE_ENCODER_VIRTUAL ,NULL ); +if (IS_ERR (encoder)) +return PTR_ERR (encoder); + +drm_encoder_helper_add (encoder, &rcar_du_wb_enc_helper_funcs); + + encoder->possible_crtcs =drm_crtc_mask (&rcrtc->crtc); +drm_connector_helper_add (&wb_conn->base, &rcar_du_wb_conn_helper_funcs); -return drm_writeback_connector_init (&rcdu->ddev, wb_conn, - &rcar_du_wb_conn_funcs, - &rcar_du_wb_enc_helper_funcs, - writeback_formats, -ARRAY_SIZE (writeback_formats), -1 <<drm_crtc_index (&rcrtc->crtc)); +return drmm_writeback_connector_init (&rcdu->ddev, wb_conn, + &rcar_du_wb_conn_funcs, + encoder, + writeback_formats, +ARRAY_SIZE (writeback_formats)); } void rcar_du_writeback_setup(struct rcar_du_crtc *rcrtc,
Signature · 1 line
2.47.2
PATCH v3 6/8 drm/vc4: use drmm_writeback_connector_init()
In reply to Dmitry BaryshkovUse drmm_plain_encoder_alloc() to allocate simple encoder and drmm_writeback_connector_init() in order to initialize writeback connector instance.
--- drivers/gpu/drm/vc4/vc4_txp.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/gpu/drm/vc4/vc4_txp.c +4 -5
@@ -377,7 +377,6 @@ vc4_txp_connector_detect(struct drm_connector *connector, bool force)static const struct drm_connector_funcs vc4_txp_connector_funcs = { .detect = vc4_txp_connector_detect, .fill_modes = drm_helper_probe_single_connector_modes, - .destroy = drm_connector_cleanup, .reset = drm_atomic_helper_connector_reset, .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
@@ -601,10 +600,10 @@ static int vc4_txp_bind(struct device *dev, struct device *master, void *data)drm_connector_helper_add (&txp->connector.base, &vc4_txp_connector_helper_funcs); - ret =drm_writeback_connector_init_with_encoder (drm, &txp->connector, - encoder, - &vc4_txp_connector_funcs, - drm_fmts,ARRAY_SIZE (drm_fmts)); + ret =drmm_writeback_connector_init (drm, &txp->connector, + &vc4_txp_connector_funcs, + encoder, + drm_fmts,ARRAY_SIZE (drm_fmts));if (ret)return ret;
Signature · 1 line
2.47.2
PATCH v3 7/8 drm: writeback: drop excess connector initialization functions
In reply to Dmitry BaryshkovNow as all drivers have been converted to drmm_writeback_connector_init(), drop drm_writeback_connector_init() and drm_writeback_connector::encoder field, they are unused now.
--- drivers/gpu/drm/drm_writeback.c | 55 ----------------------------------------- include/drm/drm_writeback.h | 18 -------------- 2 files changed, 73 deletions(-)
drivers/gpu/drm/drm_writeback.c +0 -55
@@ -142,61 +142,6 @@ static int create_writeback_properties(struct drm_device *dev)return 0 ; } -static const struct drm_encoder_funcs drm_writeback_encoder_funcs = { - .destroy = drm_encoder_cleanup, -}; - -/** -* drm_writeback_connector_init - Initialize a writeback connector and its properties -* @dev: DRM device -* @wb_connector: Writeback connector to initialize -* @con_funcs: Connector funcs vtable -* @enc_helper_funcs: Encoder helper funcs vtable to be used by the internal encoder -* @formats: Array of supported pixel formats for the writeback engine -* @n_formats: Length of the formats array -* @possible_crtcs: possible crtcs for the internal writeback encoder -* -* This function creates the writeback-connector-specific properties if they -* have not been already created, initializes the connector as -* type DRM_MODE_CONNECTOR_WRITEBACK, and correctly initializes the property -* values. It will also create an internal encoder associated with the -* drm_writeback_connector and set it to use the @enc_helper_funcs vtable for -* the encoder helper. -* -* Drivers should always use this function instead of drm_connector_init() to -* set up writeback connectors. -* -* Returns: 0 on success, or a negative error code -*/ -int drm_writeback_connector_init (struct drm_device *dev, -struct drm_writeback_connector *wb_connector, -const struct drm_connector_funcs *con_funcs, -const struct drm_encoder_helper_funcs *enc_helper_funcs, -const u32 *formats,int n_formats, -u32 possible_crtcs) -{ -int ret =0 ; - -drm_encoder_helper_add (&wb_connector->encoder, enc_helper_funcs); - - wb_connector->encoder.possible_crtcs = possible_crtcs; - - ret =drm_encoder_init (dev, &wb_connector->encoder, - &drm_writeback_encoder_funcs, -DRM_MODE_ENCODER_VIRTUAL ,NULL ); -if (ret) -return ret; - - ret =drm_writeback_connector_init_with_encoder (dev, wb_connector, &wb_connector->encoder, - con_funcs, formats, n_formats); - -if (ret) -drm_encoder_cleanup (&wb_connector->encoder); - -return ret; -} -EXPORT_SYMBOL (drm_writeback_connector_init); -static void delete_writeback_properties (struct drm_device *dev) {if (dev->mode_config.writeback_pixel_formats_property) {
include/drm/drm_writeback.h +0 -18
@@ -24,17 +24,6 @@ struct drm_writeback_connector {*/ struct drm_connector base; -/** -* @encoder: Internal encoder used by the connector to fulfill -* the DRM framework requirements. The users of the -* @drm_writeback_connector control the behaviour of the @encoder -* by passing the @enc_funcs parameter to drm_writeback_connector_init() -* function. -* For users of drm_writeback_connector_init_with_encoder(), this field -* is not valid as the encoder is managed within their drivers. -*/ -struct drm_encoder encoder; -/** * @pixel_formats_blob_ptr: *
@@ -148,13 +137,6 @@ drm_connector_to_writeback(struct drm_connector *connector) return container_of(connector, struct drm_writeback_connector, base); } -int drm_writeback_connector_init (struct drm_device *dev, -struct drm_writeback_connector *wb_connector, -const struct drm_connector_funcs *con_funcs, -const struct drm_encoder_helper_funcs *enc_helper_funcs, -const u32 *formats,int n_formats, -u32 possible_crtcs); - int drm_writeback_connector_init_with_encoder(struct drm_device *dev, struct drm_writeback_connector *wb_connector, struct drm_encoder *enc,
Signature · 1 line
2.47.2
PATCH v3 8/8 drm: writeback: rename drm_writeback_connector_init_with_encoder()
In reply to Dmitry BaryshkovRename drm_writeback_connector_init_with_encoder() to drm_writeback_connector_init() and adapt its interface to follow drmm_writeback_connector_init().
--- drivers/gpu/drm/drm_writeback.c | 14 +++++++------- include/drm/drm_writeback.h | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-)
drivers/gpu/drm/drm_writeback.c +7 -7
@@ -235,7 +235,7 @@ static int __drm_writeback_connector_init(struct drm_device *dev, }/** -* drm_writeback_connector_init_with_encoder - Initialize a writeback connector with +* drm_writeback_connector_init - Initialize a writeback connector with * a custom encoder * * @dev: DRM device
@@ -263,11 +263,11 @@ static int __drm_writeback_connector_init(struct drm_device *dev,* * Returns: 0 on success, or a negative error code */ -int drm_writeback_connector_init_with_encoder (struct drm_device *dev, -struct drm_writeback_connector *wb_connector, -struct drm_encoder *enc, -const struct drm_connector_funcs *con_funcs, -const u32 *formats,int n_formats) +int drm_writeback_connector_init (struct drm_device *dev, +struct drm_writeback_connector *wb_connector, +const struct drm_connector_funcs *con_funcs, +struct drm_encoder *enc, +const u32 *formats,int n_formats) {struct drm_connector *connector = &wb_connector->base;int ret;
@@ -284,7 +284,7 @@ int drm_writeback_connector_init_with_encoder(struct drm_device *dev,return ret; } -EXPORT_SYMBOL (drm_writeback_connector_init_with_encoder); +EXPORT_SYMBOL (drm_writeback_connector_init);/** * drm_writeback_connector_cleanup - Cleanup the writeback connector
include/drm/drm_writeback.h +5 -5
@@ -137,11 +137,11 @@ drm_connector_to_writeback(struct drm_connector *connector) return container_of(connector, struct drm_writeback_connector, base); } -int drm_writeback_connector_init_with_encoder (struct drm_device *dev, -struct drm_writeback_connector *wb_connector, -struct drm_encoder *enc, -const struct drm_connector_funcs *con_funcs,const u32 *formats, -int n_formats); +int drm_writeback_connector_init (struct drm_device *dev, +struct drm_writeback_connector *wb_connector, +const struct drm_connector_funcs *con_funcs, +struct drm_encoder *enc, +const u32 *formats,int n_formats); int drmm_writeback_connector_init(struct drm_device *dev, struct drm_writeback_connector *wb_connector,
Signature · 1 line
2.47.2