diff mbox

drm/i915: Fix mem leak in intel_sdvo_write_cmd()

Message ID alpine.LNX.2.00.1207312228270.7100@swampdragon.chaosbits.net (mailing list archive)
State New, archived
Headers show

Commit Message

Jesper Juhl July 31, 2012, 8:31 p.m. UTC
If the allocation of 'buf' succeeds but the allocation of 'msgs' fails
we'll return false and leak 'buf' when it goes out of scope.

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 drivers/gpu/drm/i915/intel_sdvo.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

 note: compile tested only due to lack of hardware.

Comments

Daniel Vetter Aug. 5, 2012, 9 p.m. UTC | #1
On Tue, Jul 31, 2012 at 10:31:15PM +0200, Jesper Juhl wrote:
> If the allocation of 'buf' succeeds but the allocation of 'msgs' fails
> we'll return false and leak 'buf' when it goes out of scope.
> 
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>

I've already merged a similar patch from Alan Cox for -fixes, should land
in 3.6 soonish.
-Daniel
Jesper Juhl Aug. 5, 2012, 9:19 p.m. UTC | #2
On Sun, 5 Aug 2012, Daniel Vetter wrote:

> On Tue, Jul 31, 2012 at 10:31:15PM +0200, Jesper Juhl wrote:
> > If the allocation of 'buf' succeeds but the allocation of 'msgs' fails
> > we'll return false and leak 'buf' when it goes out of scope.
> > 
> > Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> 
> I've already merged a similar patch from Alan Cox for -fixes, should land
> in 3.6 soonish.

Perfect.
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c
index 26a6a4d..1f73e24 100644
--- a/drivers/gpu/drm/i915/intel_sdvo.c
+++ b/drivers/gpu/drm/i915/intel_sdvo.c
@@ -444,13 +444,12 @@  static bool intel_sdvo_write_cmd(struct intel_sdvo *intel_sdvo, u8 cmd,
 	struct i2c_msg *msgs;
 	int i, ret = true;
 
-	buf = (u8 *)kzalloc(args_len * 2 + 2, GFP_KERNEL);
-	if (!buf)
-		return false;
-
+	buf = kzalloc(args_len * 2 + 2, GFP_KERNEL);
 	msgs = kcalloc(args_len + 3, sizeof(*msgs), GFP_KERNEL);
-	if (!msgs)
-		return false;
+	if (!msgs || !buf) {
+		ret = false;
+		goto out;
+	}
 
 	intel_sdvo_debug_write(intel_sdvo, cmd, args, args_len);