diff mbox series

[v2] drm/mxsfb: Switch to drmm_mode_config_init

Message ID 20231127212612.77667-1-marex@denx.de (mailing list archive)
State New, archived
Headers show
Series [v2] drm/mxsfb: Switch to drmm_mode_config_init | expand

Commit Message

Marek Vasut Nov. 27, 2023, 9:25 p.m. UTC
Switch from deprecated unmanaged drm_mode_config_init() to
managed drmm_mode_config_init(). No functional change.

Signed-off-by: Marek Vasut <marex@denx.de>
---
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: David Airlie <airlied@gmail.com>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: NXP Linux Team <linux-imx@nxp.com>
Cc: Pengutronix Kernel Team <kernel@pengutronix.de>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Stefan Agner <stefan@agner.ch>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-arm-kernel@lists.infradead.org
---
V2: Drop matching drm_mode_config_cleanup
---
 drivers/gpu/drm/mxsfb/mxsfb_drv.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Thomas Zimmermann Nov. 28, 2023, 7:53 a.m. UTC | #1
Am 27.11.23 um 22:25 schrieb Marek Vasut:
> Switch from deprecated unmanaged drm_mode_config_init() to
> managed drmm_mode_config_init(). No functional change.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> ---
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Fabio Estevam <festevam@gmail.com>
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Maxime Ripard <mripard@kernel.org>
> Cc: NXP Linux Team <linux-imx@nxp.com>
> Cc: Pengutronix Kernel Team <kernel@pengutronix.de>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Shawn Guo <shawnguo@kernel.org>
> Cc: Stefan Agner <stefan@agner.ch>
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: dri-devel@lists.freedesktop.org
> Cc: linux-arm-kernel@lists.infradead.org

Acked-by: Thomas Zimmermann <tzimmermann@suse.de>

> ---
> V2: Drop matching drm_mode_config_cleanup
> ---
>   drivers/gpu/drm/mxsfb/mxsfb_drv.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/mxsfb/mxsfb_drv.c b/drivers/gpu/drm/mxsfb/mxsfb_drv.c
> index 3bfa369b2507e..cfa3176ebe2c2 100644
> --- a/drivers/gpu/drm/mxsfb/mxsfb_drv.c
> +++ b/drivers/gpu/drm/mxsfb/mxsfb_drv.c
> @@ -248,7 +248,11 @@ static int mxsfb_load(struct drm_device *drm,
>   	pm_runtime_enable(drm->dev);
>   
>   	/* Modeset init */
> -	drm_mode_config_init(drm);
> +	ret = drmm_mode_config_init(drm);
> +	if (ret) {
> +		dev_err(drm->dev, "Failed to initialize mode config\n");
> +		goto err_vblank;
> +	}
>   
>   	ret = mxsfb_kms_init(mxsfb);
>   	if (ret < 0) {
> @@ -311,7 +315,6 @@ static int mxsfb_load(struct drm_device *drm,
>   static void mxsfb_unload(struct drm_device *drm)
>   {
>   	drm_kms_helper_poll_fini(drm);
> -	drm_mode_config_cleanup(drm);
>   
>   	pm_runtime_get_sync(drm->dev);
>   	mxsfb_irq_uninstall(drm);
Maxime Ripard Nov. 28, 2023, 8:27 a.m. UTC | #2
Hi,

On Mon, Nov 27, 2023 at 10:25:38PM +0100, Marek Vasut wrote:
> Switch from deprecated unmanaged drm_mode_config_init() to
> managed drmm_mode_config_init(). No functional change.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> ---
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Fabio Estevam <festevam@gmail.com>
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Maxime Ripard <mripard@kernel.org>
> Cc: NXP Linux Team <linux-imx@nxp.com>
> Cc: Pengutronix Kernel Team <kernel@pengutronix.de>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Shawn Guo <shawnguo@kernel.org>
> Cc: Stefan Agner <stefan@agner.ch>
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: dri-devel@lists.freedesktop.org
> Cc: linux-arm-kernel@lists.infradead.org

This is only somewhat related to that patch, but mksfb_drm_private is
allocated with devm and holds the planes, crtcs and encoders. This is
unsafe, leads to UAF, and should be converted to a drmm allocation too
(in another patch of course)

Maxime
Thomas Zimmermann Nov. 28, 2023, 9:31 a.m. UTC | #3
Hi

Am 28.11.23 um 09:27 schrieb Maxime Ripard:
> Hi,
> 
> On Mon, Nov 27, 2023 at 10:25:38PM +0100, Marek Vasut wrote:
>> Switch from deprecated unmanaged drm_mode_config_init() to
>> managed drmm_mode_config_init(). No functional change.
>>
>> Signed-off-by: Marek Vasut <marex@denx.de>
>> ---
>> Cc: Daniel Vetter <daniel@ffwll.ch>
>> Cc: David Airlie <airlied@gmail.com>
>> Cc: Fabio Estevam <festevam@gmail.com>
>> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
>> Cc: Maxime Ripard <mripard@kernel.org>
>> Cc: NXP Linux Team <linux-imx@nxp.com>
>> Cc: Pengutronix Kernel Team <kernel@pengutronix.de>
>> Cc: Sascha Hauer <s.hauer@pengutronix.de>
>> Cc: Shawn Guo <shawnguo@kernel.org>
>> Cc: Stefan Agner <stefan@agner.ch>
>> Cc: Thomas Zimmermann <tzimmermann@suse.de>
>> Cc: dri-devel@lists.freedesktop.org
>> Cc: linux-arm-kernel@lists.infradead.org
> 
> This is only somewhat related to that patch, but mksfb_drm_private is
> allocated with devm and holds the planes, crtcs and encoders. This is
> unsafe, leads to UAF, and should be converted to a drmm allocation too
> (in another patch of course)

To add to this, the whole driver's probe/remove should be converted to 
managed code. There's irq and pm code that could likely be updated. 
Marek, if you have the means, patches are welcome.

Best regards
Thomas

> 
> Maxime
diff mbox series

Patch

diff --git a/drivers/gpu/drm/mxsfb/mxsfb_drv.c b/drivers/gpu/drm/mxsfb/mxsfb_drv.c
index 3bfa369b2507e..cfa3176ebe2c2 100644
--- a/drivers/gpu/drm/mxsfb/mxsfb_drv.c
+++ b/drivers/gpu/drm/mxsfb/mxsfb_drv.c
@@ -248,7 +248,11 @@  static int mxsfb_load(struct drm_device *drm,
 	pm_runtime_enable(drm->dev);
 
 	/* Modeset init */
-	drm_mode_config_init(drm);
+	ret = drmm_mode_config_init(drm);
+	if (ret) {
+		dev_err(drm->dev, "Failed to initialize mode config\n");
+		goto err_vblank;
+	}
 
 	ret = mxsfb_kms_init(mxsfb);
 	if (ret < 0) {
@@ -311,7 +315,6 @@  static int mxsfb_load(struct drm_device *drm,
 static void mxsfb_unload(struct drm_device *drm)
 {
 	drm_kms_helper_poll_fini(drm);
-	drm_mode_config_cleanup(drm);
 
 	pm_runtime_get_sync(drm->dev);
 	mxsfb_irq_uninstall(drm);