[PATCH 05/47] intel, gma500, lvds: Fix use after free and mem leak in psb_intel_lvds_init()
Alan Cox
alan at lxorguk.ukuu.org.uk
Thu Mar 8 08:00:58 PST 2012
From: Jesper Juhl <jj at chaosbits.net>
In psb_intel_lvds_init(), if we fail to allocate memory for
'psb_intel_connector' we free the memory we previously allocated for
'psb_intel_encoder', but we then proceed to use that free'd pointer
when we do 'psb_intel_encoder->dev_priv = lvds_priv;'.
We may also leak the memory we allocated for 'psb_intel_encoder' if we
'goto failed_connector;' and the variable goes out of scope.
While I was there anyway, I also removed the pointless 'if
(psb_intel_connector)' before freeing it at the 'failed_connector:'
label - kfree() deals gracefully with NULL pointers, so it is not
needed.
Signed-off-by: Jesper Juhl <jj at chaosbits.net>
Signed-off-by: Alan Cox <alan at linux.intel.com>
---
drivers/gpu/drm/gma500/psb_intel_lvds.c | 9 ++++-----
1 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/gma500/psb_intel_lvds.c b/drivers/gpu/drm/gma500/psb_intel_lvds.c
index 69a9651..c83f5b5 100644
--- a/drivers/gpu/drm/gma500/psb_intel_lvds.c
+++ b/drivers/gpu/drm/gma500/psb_intel_lvds.c
@@ -713,7 +713,6 @@ void psb_intel_lvds_init(struct drm_device *dev,
psb_intel_encoder =
kzalloc(sizeof(struct psb_intel_encoder), GFP_KERNEL);
-
if (!psb_intel_encoder) {
dev_err(dev->dev, "psb_intel_encoder allocation error\n");
return;
@@ -721,10 +720,9 @@ void psb_intel_lvds_init(struct drm_device *dev,
psb_intel_connector =
kzalloc(sizeof(struct psb_intel_connector), GFP_KERNEL);
-
if (!psb_intel_connector) {
- kfree(psb_intel_encoder);
dev_err(dev->dev, "psb_intel_connector allocation error\n");
+ goto failed_encoder;
}
lvds_priv = kzalloc(sizeof(struct psb_intel_lvds_priv), GFP_KERNEL);
@@ -862,7 +860,8 @@ failed_blc_i2c:
drm_encoder_cleanup(encoder);
drm_connector_cleanup(connector);
failed_connector:
- if (psb_intel_connector)
- kfree(psb_intel_connector);
+ kfree(psb_intel_connector);
+failed_encoder:
+ kfree(psb_intel_encoder);
}
More information about the dri-devel
mailing list