Skip to contentSkip to conversation

drm/mxsfb: Switch to drmm_mode_config_init

PATCH In review Marek Vasut 3 participants 4 messages Nov 27, 2023 – Nov 28, 2023

Subsystems (4)
lore
Share & tools
lore

Marek Vasut

author maintainer
#0 lore raw

PATCH v2 1/1 drm/mxsfb: Switch to drmm_mode_config_init

Switch from deprecated unmanaged drm_mode_config_init() to managed drmm_mode_config_init(). No functional change.

---
Cc: Daniel Vetter <[email protected]>
Cc: David Airlie <[email protected]>
Cc: Fabio Estevam <[email protected]>
Cc: Maarten Lankhorst <[email protected]>
Cc: Maxime Ripard <[email protected]>
Cc: NXP Linux Team <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: Stefan Agner <[email protected]>
Cc: Thomas Zimmermann <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
V2: Drop matching drm_mode_config_cleanup

---
 drivers/gpu/drm/mxsfb/mxsfb_drv.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/mxsfb/mxsfb_drv.c +5 -2
index 3bfa369b2507e..cfa3176ebe2c2 100644
@@ -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);
Signature · 1 line
2.42.0
maintainer Acked-by on v2 1/1
#1 lore raw

Am 27.11.23 um 22:25 schrieb Marek Vasut:

Quoted 4 lines

Switch from deprecated unmanaged drm_mode_config_init() to managed drmm_mode_config_init(). No functional change.

Quoted 14 lines

---
Cc: Daniel Vetter <[email protected]>
Cc: David Airlie <[email protected]>
Cc: Fabio Estevam <[email protected]>
Cc: Maarten Lankhorst <[email protected]>
Cc: Maxime Ripard <[email protected]>
Cc: NXP Linux Team <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: Stefan Agner <[email protected]>
Cc: Thomas Zimmermann <[email protected]>
Cc: [email protected]
Cc: [email protected]

Quoted 31 lines

---
V2: Drop matching drm_mode_config_cleanup

---
  drivers/gpu/drm/mxsfb/mxsfb_drv.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/mxsfb/mxsfb_drv.c +5 -2
index 3bfa369b2507e..cfa3176ebe2c2 100644
@@ -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);
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
maintainer
#2 lore raw
In reply to Marek Vasut

Hi,

Quoted 4 lines · Marek Vasut

Switch from deprecated unmanaged drm_mode_config_init() to managed drmm_mode_config_init(). No functional change.

Quoted 14 lines

---
Cc: Daniel Vetter <[email protected]>
Cc: David Airlie <[email protected]>
Cc: Fabio Estevam <[email protected]>
Cc: Maarten Lankhorst <[email protected]>
Cc: Maxime Ripard <[email protected]>
Cc: NXP Linux Team <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: Stefan Agner <[email protected]>
Cc: Thomas Zimmermann <[email protected]>
Cc: [email protected]
Cc: [email protected]

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

#3 lore raw

Hi

Am 28.11.23 um 09:27 schrieb Maxime Ripard:

Quoted 22 lines

Hi,

Quoted 4 lines · Marek Vasut

Switch from deprecated unmanaged drm_mode_config_init() to managed drmm_mode_config_init(). No functional change.

Quoted 14 lines

---
Cc: Daniel Vetter <[email protected]>
Cc: David Airlie <[email protected]>
Cc: Fabio Estevam <[email protected]>
Cc: Maarten Lankhorst <[email protected]>
Cc: Maxime Ripard <[email protected]>
Cc: NXP Linux Team <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: Stefan Agner <[email protected]>
Cc: Thomas Zimmermann <[email protected]>
Cc: [email protected]
Cc: [email protected]

Quoted 4 lines

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

Quoted 2 lines

Maxime

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)