All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Diogo Silva" <diogompaissilva@gmail.com>
Cc: Frank.Li@kernel.org, dri-devel@lists.freedesktop.org,
	imx@lists.linux.dev, linux-amlogic@lists.infradead.org,
	wsa+renesas@sang-engineering.com, neil.armstrong@linaro.org
Subject: Re: [PATCH v2 11/15] drm/hisilicon/kirin: remove dependency on DRM simple helpers
Date: Mon, 20 Jul 2026 15:50:55 +0000	[thread overview]
Message-ID: <20260720155055.EEC5D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260720-drm_simple_encoder_init-v2-11-5020b630668a@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [Critical] The `dsi_data` structure, which embeds the `drm_encoder` object via `dw_dsi`, is allocated using `devm_kzalloc`. This violates DRM lifetime rules and leads to a use-after-free when the platform device unbinds.
--

--- Patch [11]: [PATCH v2 11/15] drm/hisilicon/kirin: remove dependency on DRM simple helpers ---
commit b9a0117f6ac1e860030dfb53be58e44730659ad8
Author: Diogo Silva <diogompaissilva@gmail.com>

drm/hisilicon/kirin: remove dependency on DRM simple helpers

This patch removes the deprecated simple KMS helpers by open-coding
drm_simple_encoder_init() to call drm_encoder_init() directly and
providing driver-local drm_encoder_funcs.

> diff --git a/drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c b/drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c
> index 15042365dec00..62c5bd3277da1 100644
> --- a/drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c
> +++ b/drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c

[ ... ]

> @@ -687,6 +687,10 @@ static int dsi_encoder_atomic_check(struct drm_encoder *encoder,
>  	return 0;
>  }
>  
> +static const struct drm_encoder_funcs dw_encoder_funcs = {
> +	.destroy = drm_encoder_cleanup,

[Severity: Critical]
This is a pre-existing issue, but could this setup lead to a use-after-free
when the platform device unbinds?

The encoder is embedded in the dsi_data structure, which is allocated
using devm_kzalloc() in dsi_probe():

drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c:dsi_probe() {
    ...
    data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
    ...
}

If userspace holds an open file descriptor when the platform device unbinds,
the DRM device and its mode objects will outlive the platform device. The
devres cleanup will free the dsi_data memory, but the DRM device will still
hold a pointer to the encoder in its internal lists.

When the DRM device is finally released, drm_mode_config_cleanup() will
iterate over its encoder list and invoke this .destroy callback
(drm_encoder_cleanup) on the already-freed memory.

Since you are refactoring the encoder initialization here, would this be a
good time to transition to drmm_encoder_alloc() or drmm_kzalloc() to tie the
allocation lifetime to the DRM device instead of the platform device?

> +};
> +
>  static const struct drm_encoder_helper_funcs dw_encoder_helper_funcs = {
>  	.atomic_check	= dsi_encoder_atomic_check,
>  	.mode_valid	= dsi_encoder_mode_valid,

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260720-drm_simple_encoder_init-v2-0-5020b630668a@gmail.com?part=11

WARNING: multiple messages have this Message-ID (diff)
From: sashiko-bot@kernel.org
To: "Diogo Silva" <diogompaissilva@gmail.com>
Cc: Frank.Li@kernel.org, dri-devel@lists.freedesktop.org,
	imx@lists.linux.dev, linux-amlogic@lists.infradead.org,
	wsa+renesas@sang-engineering.com, neil.armstrong@linaro.org
Subject: Re: [PATCH v2 11/15] drm/hisilicon/kirin: remove dependency on DRM simple helpers
Date: Mon, 20 Jul 2026 15:50:55 +0000	[thread overview]
Message-ID: <20260720155055.EEC5D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260720-drm_simple_encoder_init-v2-11-5020b630668a@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [Critical] The `dsi_data` structure, which embeds the `drm_encoder` object via `dw_dsi`, is allocated using `devm_kzalloc`. This violates DRM lifetime rules and leads to a use-after-free when the platform device unbinds.
--

--- Patch [11]: [PATCH v2 11/15] drm/hisilicon/kirin: remove dependency on DRM simple helpers ---
commit b9a0117f6ac1e860030dfb53be58e44730659ad8
Author: Diogo Silva <diogompaissilva@gmail.com>

drm/hisilicon/kirin: remove dependency on DRM simple helpers

This patch removes the deprecated simple KMS helpers by open-coding
drm_simple_encoder_init() to call drm_encoder_init() directly and
providing driver-local drm_encoder_funcs.

> diff --git a/drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c b/drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c
> index 15042365dec00..62c5bd3277da1 100644
> --- a/drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c
> +++ b/drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c

[ ... ]

> @@ -687,6 +687,10 @@ static int dsi_encoder_atomic_check(struct drm_encoder *encoder,
>  	return 0;
>  }
>  
> +static const struct drm_encoder_funcs dw_encoder_funcs = {
> +	.destroy = drm_encoder_cleanup,

[Severity: Critical]
This is a pre-existing issue, but could this setup lead to a use-after-free
when the platform device unbinds?

The encoder is embedded in the dsi_data structure, which is allocated
using devm_kzalloc() in dsi_probe():

drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c:dsi_probe() {
    ...
    data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
    ...
}

If userspace holds an open file descriptor when the platform device unbinds,
the DRM device and its mode objects will outlive the platform device. The
devres cleanup will free the dsi_data memory, but the DRM device will still
hold a pointer to the encoder in its internal lists.

When the DRM device is finally released, drm_mode_config_cleanup() will
iterate over its encoder list and invoke this .destroy callback
(drm_encoder_cleanup) on the already-freed memory.

Since you are refactoring the encoder initialization here, would this be a
good time to transition to drmm_encoder_alloc() or drmm_kzalloc() to tie the
allocation lifetime to the DRM device instead of the platform device?

> +};
> +
>  static const struct drm_encoder_helper_funcs dw_encoder_helper_funcs = {
>  	.atomic_check	= dsi_encoder_atomic_check,
>  	.mode_valid	= dsi_encoder_mode_valid,

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260720-drm_simple_encoder_init-v2-0-5020b630668a@gmail.com?part=11

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

  reply	other threads:[~2026-07-20 15:50 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-20 15:40 [PATCH v2 00/15] drm/drm_simple: remove drm_simple_encoder_init Diogo Silva
2026-07-20 15:40 ` Diogo Silva
2026-07-20 15:40 ` [PATCH v2 01/15] drm/exynos: remove dependency on DRM simple helpers Diogo Silva
2026-07-20 15:40   ` Diogo Silva
2026-07-20 15:52   ` sashiko-bot
2026-07-20 15:52     ` sashiko-bot
2026-07-20 15:40 ` [PATCH v2 02/15] drm/xlnx/zynqmp_dpsub: " Diogo Silva
2026-07-20 15:40   ` Diogo Silva
2026-07-20 17:49   ` Pandey, Radhey Shyam
2026-07-20 17:49     ` Pandey, Radhey Shyam
2026-07-20 15:40 ` [PATCH v2 03/15] drm/tegra: " Diogo Silva
2026-07-20 15:40   ` Diogo Silva
2026-07-20 15:40 ` [PATCH v2 04/15] drm/fsl-dcu: " Diogo Silva
2026-07-20 15:40   ` Diogo Silva
2026-07-20 15:40 ` [PATCH v2 05/15] drm/kmb: " Diogo Silva
2026-07-20 15:40   ` Diogo Silva
2026-07-20 15:40 ` [PATCH v2 06/15] drm/virtio: " Diogo Silva
2026-07-20 15:40   ` Diogo Silva
2026-07-20 16:00   ` sashiko-bot
2026-07-20 16:00     ` sashiko-bot
2026-07-20 15:40 ` [PATCH v2 07/15] drm/tidss: " Diogo Silva
2026-07-20 15:40   ` Diogo Silva
2026-07-20 16:08   ` sashiko-bot
2026-07-20 16:08     ` sashiko-bot
2026-07-20 15:40 ` [PATCH v2 08/15] drm/imx: " Diogo Silva
2026-07-20 15:40   ` Diogo Silva
2026-07-20 15:40 ` [PATCH v2 09/15] drm/mediatek: " Diogo Silva
2026-07-20 15:40   ` Diogo Silva
2026-07-20 15:40 ` [PATCH v2 10/15] drm/renesas/shmobile: " Diogo Silva
2026-07-20 15:40   ` Diogo Silva
2026-07-20 15:40 ` [PATCH v2 11/15] drm/hisilicon/kirin: " Diogo Silva
2026-07-20 15:40   ` Diogo Silva
2026-07-20 15:50   ` sashiko-bot [this message]
2026-07-20 15:50     ` sashiko-bot
2026-07-20 15:40 ` [PATCH v2 12/15] drm/arm/komeda: " Diogo Silva
2026-07-20 15:40   ` Diogo Silva
2026-07-20 15:40 ` [PATCH v2 13/15] drm/meson: " Diogo Silva
2026-07-20 15:40   ` Diogo Silva
2026-07-20 15:56   ` sashiko-bot
2026-07-20 15:56     ` sashiko-bot
2026-07-20 15:40 ` [PATCH v2 14/15] drm/drm_simple: remove deprecated drm_simple_encoder_init function Diogo Silva
2026-07-20 15:40   ` Diogo Silva
2026-07-20 15:54   ` sashiko-bot
2026-07-20 15:54     ` sashiko-bot
2026-07-20 15:40 ` [PATCH v2 15/15] Documentation/gpu: remove completed drm_simple_encoder_init() todo Diogo Silva
2026-07-20 15:40   ` Diogo Silva
2026-07-20 16:07   ` sashiko-bot
2026-07-20 16:07     ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260720155055.EEC5D1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=diogompaissilva@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=imx@lists.linux.dev \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=neil.armstrong@linaro.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=wsa+renesas@sang-engineering.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.