Skip to contentSkip to conversation

drm/i915: Don't leak VBT mode data

PATCH Applied Matt Roper 3 participants 6 messages Sep 15, 2015 – Sep 23, 2015

Subsystems (2)
lore
Share & tools
lore

Matt Roper

author
#0 lore raw

PATCH 1/1 drm/i915: Don't leak VBT mode data

We allocate memory for LVDS modes while parsing the VBT at startup, but never free this memory when the driver is unloaded, causing a small leak.

---
 drivers/gpu/drm/i915/i915_dma.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/i915/i915_dma.c +4 -0
index 066a0ef..c069550 100644
@@ -1137,6 +1137,10 @@ int i915_driver_unload(struct drm_device *dev)
 		dev_priv->vbt.child_dev = NULL;
 		dev_priv->vbt.child_dev_num = 0;
 	}
+	kfree(dev_priv->vbt.sdvo_lvds_vbt_mode);
+	dev_priv->vbt.sdvo_lvds_vbt_mode = NULL;
+	kfree(dev_priv->vbt.lfp_lvds_vbt_mode);
+	dev_priv->vbt.lfp_lvds_vbt_mode = NULL;
 
 	vga_switcheroo_unregister_client(dev->pdev);
 	vga_client_register(dev->pdev, NULL, NULL, NULL);
Signature · 6 lines
2.1.4

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Matt Roper

We allocate memory for LVDS modes while parsing the VBT at startup, but never free this memory when the driver is unloaded, causing a small leak.

We could probably use devm_*alloc functions for this kind of stuff more.

Quoted 26 lines
---
 drivers/gpu/drm/i915/i915_dma.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/i915/i915_dma.c +4 -0
index 066a0ef..c069550 100644
@@ -1137,6 +1137,10 @@ int i915_driver_unload(struct drm_device *dev)
 		dev_priv->vbt.child_dev = NULL;
 		dev_priv->vbt.child_dev_num = 0;
 	}
+	kfree(dev_priv->vbt.sdvo_lvds_vbt_mode);
+	dev_priv->vbt.sdvo_lvds_vbt_mode = NULL;
+	kfree(dev_priv->vbt.lfp_lvds_vbt_mode);
+	dev_priv->vbt.lfp_lvds_vbt_mode = NULL;
 
 	vga_switcheroo_unregister_client(dev->pdev);
 	vga_client_register(dev->pdev, NULL, NULL, NULL);
Signature · 6 lines
2.1.4

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw
Quoted 10 lines · Jani Nikula
Quoted 5 lines · Matt Roper

We allocate memory for LVDS modes while parsing the VBT at startup, but never free this memory when the driver is unloaded, causing a small leak.

We could probably use devm_*alloc functions for this kind of stuff more.

The problem with devm_* is that the lifetime of the underlying hw device doesn't stricltly match the lifetime of the drm device. Not that anything in drm gets that right (pretty far from it), but that's why I haven't gone ballastic yet with rolling out devm_* all over our init code. -Daniel

Quoted 35 lines
Quoted 28 lines

---
 drivers/gpu/drm/i915/i915_dma.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/i915/i915_dma.c +4 -0
index 066a0ef..c069550 100644
@@ -1137,6 +1137,10 @@ int i915_driver_unload(struct drm_device *dev)
 		dev_priv->vbt.child_dev = NULL;
 		dev_priv->vbt.child_dev_num = 0;
 	}
+	kfree(dev_priv->vbt.sdvo_lvds_vbt_mode);
+	dev_priv->vbt.sdvo_lvds_vbt_mode = NULL;
+	kfree(dev_priv->vbt.lfp_lvds_vbt_mode);
+	dev_priv->vbt.lfp_lvds_vbt_mode = NULL;
 
 	vga_switcheroo_unregister_client(dev->pdev);
 	vga_client_register(dev->pdev, NULL, NULL, NULL);
Signature · 6 lines
2.1.4

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
maintainer
#3 lore raw
Quoted 6 lines · Daniel Vetter
Quoted 5 lines · Jani Nikula
Quoted 4 lines · Matt Roper

We allocate memory for LVDS modes while parsing the VBT at startup, but never free this memory when the driver is unloaded, causing a small leak.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

We could probably use devm_*alloc functions for this kind of stuff more.

The problem with devm_* is that the lifetime of the underlying hw device doesn't stricltly match the lifetime of the drm device.

Is it not enough that the lifetime of the driver is bounded by the lifetime of the drm device? What is the problem you're referring to, apart from handing the hardware devm allocated memory and unreferencing the drm device?

Quoted 3 lines

Not that anything in drm gets that right (pretty far from it), but that's why I haven't gone ballastic yet with rolling out devm_* all over our init code.

I think you mean "ballistic", but, in this case, I think your typo "ballastic" is actually a more accurate description of the change. :)

BR,
Jani.

Quoted 42 lines

-Daniel

Quoted 35 lines
Quoted 28 lines

---
 drivers/gpu/drm/i915/i915_dma.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/i915/i915_dma.c +4 -0
index 066a0ef..c069550 100644
@@ -1137,6 +1137,10 @@ int i915_driver_unload(struct drm_device *dev)
 		dev_priv->vbt.child_dev = NULL;
 		dev_priv->vbt.child_dev_num = 0;
 	}
+	kfree(dev_priv->vbt.sdvo_lvds_vbt_mode);
+	dev_priv->vbt.sdvo_lvds_vbt_mode = NULL;
+	kfree(dev_priv->vbt.lfp_lvds_vbt_mode);
+	dev_priv->vbt.lfp_lvds_vbt_mode = NULL;
 
 	vga_switcheroo_unregister_client(dev->pdev);
 	vga_client_register(dev->pdev, NULL, NULL, NULL);
Signature · 6 lines
2.1.4

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw
Quoted 13 lines · Jani Nikula
Quoted 12 lines · Daniel Vetter
Quoted 10 lines · Jani Nikula
Quoted 5 lines · Matt Roper

We allocate memory for LVDS modes while parsing the VBT at startup, but never free this memory when the driver is unloaded, causing a small leak.

We could probably use devm_*alloc functions for this kind of stuff more.

Quoted 7 lines
Quoted 2 lines

The problem with devm_* is that the lifetime of the underlying hw device doesn't stricltly match the lifetime of the drm device.

Is it not enough that the lifetime of the driver is bounded by the lifetime of the drm device? What is the problem you're referring to, apart from handing the hardware devm allocated memory and unreferencing the drm device?

For udl if you unplug the physical device the struct device _will_ go away.

The drm_device otoh might be referenced by piles of other internal things (like open file descriptors, shared dma-bufs and what else) and hence very much must stick around. Of course we /should/ try to not call down into lower-level hw handling code in that state. Which all very much doesn't happen (at least in a race-free manner).

So the drm_device is not bounded by the lifetime of the underlying physical device in full generality. Which is why we can't really do any devm_* stuff in drm core.

Quoted 6 lines
Quoted 3 lines

Not that anything in drm gets that right (pretty far from it), but that's why I haven't gone ballastic yet with rolling out devm_* all over our init code.

I think you mean "ballistic", but, in this case, I think your typo "ballastic" is actually a more accurate description of the change. :)

Either way I think we should be ok with fully abusing devm_* ;-) -Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
maintainer Applied
#5 lore raw
In reply to Matt Roper
Quoted 5 lines · Matt Roper

We allocate memory for LVDS modes while parsing the VBT at startup, but never free this memory when the driver is unloaded, causing a small leak.

Pushed to drm-intel-next-queued, thanks for the patch.

BR,
Jani.

Quoted 26 lines
---
 drivers/gpu/drm/i915/i915_dma.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/i915/i915_dma.c +4 -0
index 066a0ef..c069550 100644
@@ -1137,6 +1137,10 @@ int i915_driver_unload(struct drm_device *dev)
 		dev_priv->vbt.child_dev = NULL;
 		dev_priv->vbt.child_dev_num = 0;
 	}
+	kfree(dev_priv->vbt.sdvo_lvds_vbt_mode);
+	dev_priv->vbt.sdvo_lvds_vbt_mode = NULL;
+	kfree(dev_priv->vbt.lfp_lvds_vbt_mode);
+	dev_priv->vbt.lfp_lvds_vbt_mode = NULL;
 
 	vga_switcheroo_unregister_client(dev->pdev);
 	vga_client_register(dev->pdev, NULL, NULL, NULL);
Signature · 6 lines
2.1.4

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx