drm: Open-code drm_simple_encoder_init() in several drivers
Subsystems (8)
cover drm: Open-code drm_simple_encoder_init() in several drivers
drm_simple_encoder_init() is a thin wrapper around drm_encoder_init() that provides a simple destroy-only encoder funcs struct. This series removes the dependency on drm_simple_kms_helper in six drivers by open-coding the encoder initialization directly.
Each patch adds a static drm_encoder_funcs struct with a destroy callback and replaces drm_simple_encoder_init() with drm_encoder_init(). The drm_simple_kms_helper.h include is removed where it is no longer needed.
Drivers converted in this series:
- fsl-dcu
- tidss
- virtio
- meson (encoder_cvbs, encoder_hdmi, encoder_dsi)
Naman Arora (6):
drm/fsl-dcu: Open-code drm_simple_encoder_init() drm/tidss: Open-code drm_simple_encoder_init() drm/virtio: Open-code drm_simple_encoder_init() drm/meson: Open-code drm_simple_encoder_init() in encoder_cvbs drm/meson: Open-code drm_simple_encoder_init() in encoder_hdmi drm/meson: Open-code drm_simple_encoder_init() in encoder_dsi
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c | 10 +++++++--- drivers/gpu/drm/meson/meson_encoder_cvbs.c | 10 +++++++--- drivers/gpu/drm/meson/meson_encoder_dsi.c | 10 +++++++--- drivers/gpu/drm/meson/meson_encoder_hdmi.c | 10 +++++++--- drivers/gpu/drm/tidss/tidss_encoder.c | 10 +++++++--- drivers/gpu/drm/virtio/virtgpu_display.c | 8 ++++++-- 6 files changed, 41 insertions(+), 17 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/6 drm/fsl-dcu: Open-code drm_simple_encoder_init()
The helper drm_simple_encoder_init() is a thin wrapper around drm_encoder_init() with a simple destroy-only encoder funcs struct. Remove the dependency on drm_simple_kms_helper by open-coding the encoder initialization directly in the driver.
--- drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c +7 -3
@@ -14,11 +14,14 @@#include <drm/drm_of.h> #include <drm/drm_panel.h> #include <drm/drm_probe_helper.h> -#include <drm/drm_simple_kms_helper.h> #include "fsl_dcu_drm_drv.h" #include "fsl_tcon.h" +static const struct drm_encoder_funcs fsl_dcu_drm_encoder_funcs = { + .destroy = drm_encoder_cleanup, +}; +int fsl_dcu_drm_encoder_create (struct fsl_dcu_drm_device *fsl_dev,struct drm_crtc *crtc) {
@@ -31,8 +34,9 @@ int fsl_dcu_drm_encoder_create(struct fsl_dcu_drm_device *fsl_dev,if (fsl_dev->tcon)fsl_tcon_bypass_enable (fsl_dev->tcon); - ret =drm_simple_encoder_init (fsl_dev->drm, encoder, -DRM_MODE_ENCODER_LVDS ); + ret =drm_encoder_init (fsl_dev->drm, encoder, + &fsl_dcu_drm_encoder_funcs, +DRM_MODE_ENCODER_LVDS ,NULL );if (ret <0 )return ret;
Signature · 1 line
2.20.1
PATCH 2/6 drm/tidss: Open-code drm_simple_encoder_init()
In reply to Naman AroraThe helper drm_simple_encoder_init() is a thin wrapper around drm_encoder_init() with a simple destroy-only encoder funcs struct. Remove the dependency on drm_simple_kms_helper by open-coding the encoder initialization directly in the driver.
--- drivers/gpu/drm/tidss/tidss_encoder.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/tidss/tidss_encoder.c +7 -3
@@ -13,7 +13,6 @@#include <drm/drm_modeset_helper_vtables.h> #include <drm/drm_panel.h> #include <drm/drm_of.h> -#include <drm/drm_simple_kms_helper.h> #include "tidss_crtc.h" #include "tidss_drv.h"
@@ -81,6 +80,10 @@ static const struct drm_bridge_funcs tidss_bridge_funcs = { .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state, }; +static const struct drm_encoder_funcs tidss_drm_encoder_funcs = { + .destroy = drm_encoder_cleanup, +}; +int tidss_encoder_create (struct tidss_device *tidss,struct drm_bridge *next_bridge,u32 encoder_type,u32 possible_crtcs)
@@ -95,8 +98,9 @@ int tidss_encoder_create(struct tidss_device *tidss,if (IS_ERR (t_enc))return PTR_ERR (t_enc); - ret =drm_simple_encoder_init (&tidss->ddev, &t_enc->encoder, - encoder_type); + ret =drm_encoder_init (&tidss->ddev, &t_enc->encoder, + &tidss_drm_encoder_funcs, + encoder_type,NULL );if (ret)return ret;
Signature · 1 line
2.20.1
[email protected]
AI reviewRe: [PATCH 2/6] drm/tidss: Open-code drm_simple_encoder_init()
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Use-After-Free on driver unbind or probe failure due to mixed devm/drmm lifecycles for the combined encoder/bridge structure. --
commit b7421f2a0634d4a6488478cb165139b91f9afc7d
Author: Naman Arora <[email protected]>
drm/tidss: Open-code drm_simple_encoder_init()
The helper drm_simple_encoder_init() is a thin wrapper around drm_encoder_init() with a simple destroy-only encoder funcs struct. Remove the dependency on drm_simple_kms_helper by open-coding the encoder initialization directly in the driver.
Quoted 4 lines
drivers/gpu/drm/tidss/tidss_encoder.c +0
-0
[ ... ]
drivers/gpu/drm/tidss/tidss_encoder.c int tidss_encoder_create(struct tidss_device *tidss, · line 103
Quoted 9 lines
drivers/gpu/drm/tidss/tidss_encoder.c +3
-2@@ -95,8 +98,9 @@ int tidss_encoder_create(struct tidss_device *tidss,if (IS_ERR (t_enc))return PTR_ERR (t_enc); - ret =drm_simple_encoder_init (&tidss->ddev, &t_enc->encoder, - encoder_type); + ret =drm_encoder_init (&tidss->ddev, &t_enc->encoder, + &tidss_drm_encoder_funcs, + encoder_type,NULL );
[Severity: High]
This is a pre-existing issue, but could this mix of devm and drm lifecycles lead to a use-after-free during driver unbind or probe failure?
The t_enc struct is allocated using devm_drm_bridge_alloc(), giving it an initial refcount of 1. Here, drm_encoder_init() registers the embedded t_enc->encoder. Later in this function, drm_bridge_attach() will increase the refcount to 2.
During driver unbind, devres LIFO cleanup executes the bridge release action, calling drm_bridge_put() and dropping the refcount to 1. Next, the drm_device release action triggers drm_mode_config_cleanup(), which calls drm_encoder_cleanup().
Inside drm_encoder_cleanup(), calling drm_bridge_detach() drops the final refcount to 0, causing t_enc to be freed. Immediately after that, drm_encoder_cleanup() accesses the now-freed encoder structure.
A similar issue appears to happen if drm_bridge_attach() fails during probe, as devres would free t_enc, leaving a dangling pointer for drm_mode_config_cleanup() to trip over.
Quoted 3 lines
drivers/gpu/drm/tidss/tidss_encoder.c +0
-0if (ret)return ret;
Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2 _______________________________________________ linux-amlogic mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-amlogic
PATCH 3/6 drm/virtio: Open-code drm_simple_encoder_init()
In reply to Naman AroraThe helper drm_simple_encoder_init() is a thin wrapper around drm_encoder_init() with a simple destroy-only encoder funcs struct. Remove the dependency on drm_simple_kms_helper by open-coding the encoder initialization directly in the driver.
--- drivers/gpu/drm/virtio/virtgpu_display.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/virtio/virtgpu_display.c +6 -2
@@ -32,7 +32,6 @@#include <drm/drm_gem_framebuffer_helper.h> #include <drm/drm_print.h> #include <drm/drm_probe_helper.h> -#include <drm/drm_simple_kms_helper.h> #include <drm/drm_vblank.h> #include <drm/drm_vblank_helper.h>
@@ -271,6 +270,10 @@ static const struct drm_connector_funcs virtio_gpu_connector_funcs = { .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, }; +static const struct drm_encoder_funcs virtio_gpu_drm_encoder_funcs = { + .destroy = drm_encoder_cleanup, +}; +static int vgdev_output_init (struct virtio_gpu_device *vgdev,int index) {struct drm_device *dev = vgdev->ddev;
@@ -306,7 +309,8 @@ static int vgdev_output_init(struct virtio_gpu_device *vgdev, int index)if (vgdev->has_edid)drm_connector_attach_edid_property (connector); -drm_simple_encoder_init (dev, encoder,DRM_MODE_ENCODER_VIRTUAL ); +drm_encoder_init (dev, encoder, &virtio_gpu_drm_encoder_funcs, +DRM_MODE_ENCODER_VIRTUAL ,NULL );drm_encoder_helper_add (encoder, &virtio_gpu_enc_helper_funcs); encoder->possible_crtcs =1 << index;
Signature · 1 line
2.20.1
[email protected]
AI reviewRe: [PATCH 3/6] drm/virtio: Open-code drm_simple_encoder_init()
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the return value of drm_encoder_init() is ignored, meaning failures during initialization go undetected and could lead to a kernel panic or oops. --
commit 2aea64f30defed1555346f1f9a6d96e4b1c548c9
Author: Naman Arora <[email protected]>
drm/virtio: Open-code drm_simple_encoder_init()
This commit replaces the drm_simple_encoder_init() wrapper with an open-coded drm_encoder_init() in the virtio driver to remove the dependency on the drm_simple_kms_helper.
Quoted 3 lines
drivers/gpu/drm/virtio/virtgpu_display.c +0
-0
[ ... ]
drivers/gpu/drm/virtio/virtgpu_display.c static int vgdev_output_init(struct virtio_gpu_device *vgdev, int index) · line 313
Quoted 7 lines
drivers/gpu/drm/virtio/virtgpu_display.c +2
-1@@ -306,7 +309,8 @@ static int vgdev_output_init(struct virtio_gpu_device *vgdev, int index)if (vgdev->has_edid)drm_connector_attach_edid_property (connector); -drm_simple_encoder_init (dev, encoder,DRM_MODE_ENCODER_VIRTUAL ); +drm_encoder_init (dev, encoder, &virtio_gpu_drm_encoder_funcs, +DRM_MODE_ENCODER_VIRTUAL ,NULL );
[Severity: High]
This isn't a bug introduced by this patch, but should the return value of drm_encoder_init() be checked in vgdev_output_init() here?
If drm_encoder_init() fails (for example, returning -ENOMEM if allocating the encoder name fails), the error is ignored. Does this allow the code to proceed and attach an incompletely initialized encoder to the connector, potentially leading to a NULL pointer dereference or crash later when the DRM core interacts with it?
Quoted 3 lines
drivers/gpu/drm/virtio/virtgpu_display.c +0
-0drm_encoder_helper_add (encoder, &virtio_gpu_enc_helper_funcs); encoder->possible_crtcs =1 << index;
Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3 _______________________________________________ linux-amlogic mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-amlogic
PATCH 4/6 drm/meson: Open-code drm_simple_encoder_init() in encoder_cvbs
In reply to Naman AroraThe helper drm_simple_encoder_init() is a thin wrapper around drm_encoder_init() with a simple destroy-only encoder funcs struct. Remove the dependency on drm_simple_kms_helper by open-coding the encoder initialization directly in the driver.
--- drivers/gpu/drm/meson/meson_encoder_cvbs.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/meson/meson_encoder_cvbs.c +7 -3
@@ -18,7 +18,6 @@#include <drm/drm_device.h> #include <drm/drm_edid.h> #include <drm/drm_probe_helper.h> -#include <drm/drm_simple_kms_helper.h> #include "meson_registers.h" #include "meson_vclk.h"
@@ -218,6 +217,10 @@ static const struct drm_bridge_funcs meson_encoder_cvbs_bridge_funcs = { .atomic_reset = drm_atomic_helper_bridge_reset, }; +static const struct drm_encoder_funcs meson_encoder_cvbs_drm_encoder_funcs = { + .destroy = drm_encoder_cleanup, +}; +int meson_encoder_cvbs_probe (struct meson_drm *priv) {struct drm_device *drm = priv->drm;
@@ -257,8 +260,9 @@ int meson_encoder_cvbs_probe(struct meson_drm *priv) meson_encoder_cvbs->priv = priv;/* Encoder */ - ret =drm_simple_encoder_init (priv->drm, &meson_encoder_cvbs->encoder, -DRM_MODE_ENCODER_TVDAC ); + ret =drm_encoder_init (priv->drm, &meson_encoder_cvbs->encoder, + &meson_encoder_cvbs_drm_encoder_funcs, +DRM_MODE_ENCODER_TVDAC ,NULL );if (ret)return dev_err_probe (priv->dev, ret,"Failed to init CVBS encoder\n" );
Signature · 1 line
2.20.1
PATCH 5/6 drm/meson: Open-code drm_simple_encoder_init() in encoder_hdmi
The helper drm_simple_encoder_init() is a thin wrapper around drm_encoder_init() with a simple destroy-only encoder funcs struct. Remove the dependency on drm_simple_kms_helper by open-coding the encoder initialization directly in the driver.
--- drivers/gpu/drm/meson/meson_encoder_hdmi.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/meson/meson_encoder_hdmi.c +7 -3
@@ -24,7 +24,6 @@#include <drm/drm_device.h> #include <drm/drm_edid.h> #include <drm/drm_probe_helper.h> -#include <drm/drm_simple_kms_helper.h> #include <linux/media-bus-format.h> #include <linux/videodev2.h>
@@ -369,6 +368,10 @@ static const struct drm_bridge_funcs meson_encoder_hdmi_bridge_funcs = { .atomic_reset = drm_atomic_helper_bridge_reset, }; +static const struct drm_encoder_funcs meson_encoder_hdmi_drm_encoder_funcs = { + .destroy = drm_encoder_cleanup, +}; +int meson_encoder_hdmi_probe (struct meson_drm *priv) {struct meson_encoder_hdmi *meson_encoder_hdmi;
@@ -407,8 +410,9 @@ int meson_encoder_hdmi_probe(struct meson_drm *priv) meson_encoder_hdmi->priv = priv;/* Encoder */ - ret =drm_simple_encoder_init (priv->drm, &meson_encoder_hdmi->encoder, -DRM_MODE_ENCODER_TMDS ); + ret =drm_encoder_init (priv->drm, &meson_encoder_hdmi->encoder, + &meson_encoder_hdmi_drm_encoder_funcs, +DRM_MODE_ENCODER_TMDS ,NULL );if (ret) {dev_err_probe (priv->dev, ret,"Failed to init HDMI encoder\n" ); goto err_put_node;
Signature · 1 line
2.20.1
[email protected]
AI reviewRe: [PATCH 5/6] drm/meson: Open-code drm_simple_encoder_init() in encoder_hdmi
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] The drm_encoder is embedded in a devm-allocated structure but is never explicitly removed from the DRM device's encoder list on unbind, leading to a use-after-free.
- [High] Memory leak and dangling bridge pointer on probe error paths due to missing drm_bridge_remove().
--
commit b2fc3d021ba4d558d56f29caf06c9583a6e5c48f
Author: Naman Arora <[email protected]>
drm/meson: Open-code drm_simple_encoder_init() in encoder_hdmi
The helper drm_simple_encoder_init() is a thin wrapper around drm_encoder_init() with a simple destroy-only encoder funcs struct. Remove the dependency on drm_simple_kms_helper by open-coding the encoder initialization directly in the driver.
Quoted 4 lines
drivers/gpu/drm/meson/meson_encoder_hdmi.c +0
-0
[ ... ]
drivers/gpu/drm/meson/meson_encoder_hdmi.c int meson_encoder_hdmi_probe(struct meson_drm *priv) · line 415
Quoted 9 lines
drivers/gpu/drm/meson/meson_encoder_hdmi.c +3
-2@@ -407,8 +410,9 @@ int meson_encoder_hdmi_probe(struct meson_drm *priv) meson_encoder_hdmi->priv = priv;/* Encoder */ - ret =drm_simple_encoder_init (priv->drm, &meson_encoder_hdmi->encoder, -DRM_MODE_ENCODER_TMDS ); + ret =drm_encoder_init (priv->drm, &meson_encoder_hdmi->encoder, + &meson_encoder_hdmi_drm_encoder_funcs, +DRM_MODE_ENCODER_TMDS ,NULL );
[Severity: High]
This is a pre-existing issue, but can this lead to a use-after-free when unbinding the device?
The meson_encoder_hdmi structure, which embeds the drm_encoder, is allocated via devm_drm_bridge_alloc(). This means its memory is freed when the device unbinds. However, meson_encoder_hdmi_remove() fails to call drm_encoder_cleanup(), leaving the encoder linked in the DRM device's mode_config.encoder_list.
If a userspace process keeps the DRM device file descriptor open, the DRM device outlives the driver binding. When the DRM device is finally destroyed, drm_mode_config_cleanup() iterates over the encoder_list and calls the destroy hook on the already freed encoder:
drivers/gpu/drm/meson/meson_encoder_hdmi.c:meson_encoder_hdmi_remove() {
if (priv->encoders[MESON_ENC_HDMI]) {
meson_encoder_hdmi = priv->encoders[MESON_ENC_HDMI];
drm_bridge_remove(&meson_encoder_hdmi->bridge);
...
}
}Is it necessary to explicitly remove the encoder from the list during remove?
drivers/gpu/drm/meson/meson_encoder_hdmi.c int meson_encoder_hdmi_probe(struct meson_drm *priv) · line 418
Quoted 3 lines
drivers/gpu/drm/meson/meson_encoder_hdmi.c +0
-0if (ret) {dev_err_probe (priv->dev, ret,"Failed to init HDMI encoder\n" ); goto err_put_node;
[Severity: High]
This is a pre-existing issue, but does this error path leak the bridge and leave a dangling pointer in the global bridge list?
Earlier in meson_encoder_hdmi_probe(), drm_bridge_add() increments the bridge's reference count and adds it to the global bridge_list:
drm_bridge_add(&meson_encoder_hdmi->bridge);
If the initialization steps fail here and jump to err_put_node, the code returns without calling drm_bridge_remove(). The devm cleanup only drops the initial reference taken by devm_drm_bridge_alloc().
This leaves the bridge in the global list indefinitely. Furthermore, because the parent meson_drm structure is subsequently freed by devm upon probe failure, meson_encoder_hdmi->priv becomes a dangling pointer. If another driver searches the list via of_drm_find_and_get_bridge() and calls an op on this bridge, it could dereference the freed priv structure, causing a use-after-free crash.
Should drm_bridge_remove() be called on this and other error paths?
Quoted 1 line
}
Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5 _______________________________________________ linux-amlogic mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-amlogic
PATCH 6/6 drm/meson: Open-code drm_simple_encoder_init() in encoder_dsi
In reply to Naman AroraThe helper drm_simple_encoder_init() is a thin wrapper around drm_encoder_init() with a simple destroy-only encoder funcs struct. Remove the dependency on drm_simple_kms_helper by open-coding the encoder initialization directly in the driver.
--- drivers/gpu/drm/meson/meson_encoder_dsi.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/meson/meson_encoder_dsi.c +7 -3
@@ -10,7 +10,6 @@#include <linux/of_graph.h> #include <drm/drm_atomic_helper.h> -#include <drm/drm_simple_kms_helper.h> #include <drm/drm_bridge.h> #include <drm/drm_bridge_connector.h> #include <drm/drm_device.h>
@@ -99,6 +98,10 @@ static const struct drm_bridge_funcs meson_encoder_dsi_bridge_funcs = { .atomic_reset = drm_atomic_helper_bridge_reset, }; +static const struct drm_encoder_funcs meson_encoder_dsi_drm_encoder_funcs = { + .destroy = drm_encoder_cleanup, +}; +int meson_encoder_dsi_probe (struct meson_drm *priv) {struct meson_encoder_dsi *meson_encoder_dsi;
@@ -133,8 +136,9 @@ int meson_encoder_dsi_probe(struct meson_drm *priv) meson_encoder_dsi->priv = priv;/* Encoder */ - ret =drm_simple_encoder_init (priv->drm, &meson_encoder_dsi->encoder, -DRM_MODE_ENCODER_DSI ); + ret =drm_encoder_init (priv->drm, &meson_encoder_dsi->encoder, + &meson_encoder_dsi_drm_encoder_funcs, +DRM_MODE_ENCODER_DSI ,NULL );if (ret)return dev_err_probe (priv->dev, ret,"Failed to init DSI encoder\n" );
Signature · 1 line
2.20.1
[email protected]
AI reviewRe: [PATCH 6/6] drm/meson: Open-code drm_simple_encoder_init() in encoder_dsi
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The encoder atomic enable callback uses a sleeping polling function, which violates DRM atomic context rules. --
commit 7905b259e0fff97b6803c2360bf97ff0dc74dae2
Author: Naman Arora <[email protected]>
drm/meson: Open-code drm_simple_encoder_init() in encoder_dsi
The helper drm_simple_encoder_init() is a thin wrapper around drm_encoder_init() with a simple destroy-only encoder funcs struct. Remove the dependency on drm_simple_kms_helper by open-coding the encoder initialization directly in the driver.
Quoted 4 lines
drivers/gpu/drm/meson/meson_encoder_dsi.c +0
-0
[ ... ]
drivers/gpu/drm/meson/meson_encoder_dsi.c static const struct drm_bridge_funcs meson_encoder_dsi_bridge_funcs = { · line 99
Quoted 3 lines
drivers/gpu/drm/meson/meson_encoder_dsi.c +0
-0@@ -99,6 +98,10 @@ static const struct drm_bridge_funcs meson_encoder_dsi_bridge_funcs = { .atomic_reset = drm_atomic_helper_bridge_reset, };
[Severity: High]
This is a pre-existing issue, but does this bridge configuration cause a sleep in atomic context?
Looking at the atomic_enable path for this bridge in drivers/gpu/drm/meson/meson_encoder_dsi.c:
meson_encoder_dsi_atomic_enable()
meson_encl_load_gamma()
meson_encl_set_gamma_table()
In drivers/gpu/drm/meson/meson_venc.c, meson_encl_set_gamma_table() calls:readl_relaxed_poll_timeout(..., 10, 10000)
The readl_relaxed_poll_timeout macro expands to usleep_range when a non-zero delay is provided (like 10 here), which will cause the thread to sleep.
Since bridge atomic_enable callbacks execute in an atomic context where sleeping is strictly forbidden, could this cause kernel warnings (might_sleep) or potential deadlocks if locks are held?
Should this code path use a non-sleeping polling mechanism such as readl_relaxed_poll_timeout_atomic instead?
Quoted 6 lines
drivers/gpu/drm/meson/meson_encoder_dsi.c +4
-0+static const struct drm_encoder_funcs meson_encoder_dsi_drm_encoder_funcs = { + .destroy = drm_encoder_cleanup, +}; +int meson_encoder_dsi_probe (struct meson_drm *priv) {
Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6 _______________________________________________ linux-amlogic mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-amlogic
[email protected]
AI reviewRe: [PATCH 4/6] drm/meson: Open-code drm_simple_encoder_init() in encoder_cvbs
In reply to Naman AroraThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Use-after-free during drm_encoder_cleanup() due to bridge refcount dropping to 0. --
commit e742cfdccd21fa2f8380ad2c61f49c99edf808e1
Author: Naman Arora <[email protected]>
drm/meson: Open-code drm_simple_encoder_init() in encoder_cvbs
The helper drm_simple_encoder_init() is replaced with an open-coded drm_encoder_init() to remove the dependency on drm_simple_kms_helper. A simple destroy-only encoder funcs struct is added.
Quoted 4 lines
drivers/gpu/drm/meson/meson_encoder_cvbs.c +0
-0
[ ... ]
drivers/gpu/drm/meson/meson_encoder_cvbs.c int meson_encoder_cvbs_probe(struct meson_drm *priv) · line 265
Quoted 9 lines
drivers/gpu/drm/meson/meson_encoder_cvbs.c +3
-2@@ -257,8 +260,9 @@ int meson_encoder_cvbs_probe(struct meson_drm *priv) meson_encoder_cvbs->priv = priv;/* Encoder */ - ret =drm_simple_encoder_init (priv->drm, &meson_encoder_cvbs->encoder, -DRM_MODE_ENCODER_TVDAC ); + ret =drm_encoder_init (priv->drm, &meson_encoder_cvbs->encoder, + &meson_encoder_cvbs_drm_encoder_funcs, +DRM_MODE_ENCODER_TVDAC ,NULL );
[Severity: High]
This is a pre-existing issue, but does tying the encoder cleanup directly to drm_encoder_cleanup() lead to a use-after-free during device unbind?
If the driver is unbound while userspace holds an open DRM device reference, the platform unbind will drop the devm reference to the meson_encoder_cvbs bridge container. The bridge is then kept alive only by the attach reference.
When userspace finally closes the file descriptor, drm_mode_config_cleanup() calls the encoder's destroy hook, which maps to drm_encoder_cleanup().
Inside drm_encoder_cleanup(), it drops the final bridge reference:
drm_encoder.c:drm_encoder_cleanup() {
...
list_for_each_entry_safe(bridge, next, &tmplist, chain_node)
drm_bridge_detach(bridge);
...This frees the meson_encoder_cvbs container. However, drm_encoder_cleanup() continues to access the embedded encoder:
drm_mode_object_unregister(dev, &encoder->base);
kfree(encoder->name);
list_del(&encoder->head);
...
memset(encoder, 0, sizeof(*encoder));
}Could this sequence corrupt memory when it accesses the already freed encoder structure?
Quoted 3 lines
drivers/gpu/drm/meson/meson_encoder_cvbs.c +0
-0if (ret)return dev_err_probe (priv->dev, ret,"Failed to init CVBS encoder\n" );
Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4 _______________________________________________ linux-amlogic mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-amlogic