From patchwork Tue Jul 31 20:31:15 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesper Juhl X-Patchwork-Id: 1262021 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 453903FC71 for ; Tue, 31 Jul 2012 20:31:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4A75D9E82A for ; Tue, 31 Jul 2012 13:31:30 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from swampdragon.chaosbits.net (1010ds2-suoe.0.fullrate.dk [90.184.90.115]) by gabe.freedesktop.org (Postfix) with ESMTP id 513679E70A for ; Tue, 31 Jul 2012 13:31:18 -0700 (PDT) Received: by swampdragon.chaosbits.net (Postfix, from userid 1000) id F0DA49403D; Tue, 31 Jul 2012 22:31:15 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by swampdragon.chaosbits.net (Postfix) with ESMTP id EF19D9403B; Tue, 31 Jul 2012 22:31:15 +0200 (CEST) Date: Tue, 31 Jul 2012 22:31:15 +0200 (CEST) From: Jesper Juhl To: David Airlie Subject: [PATCH] drm/i915: Fix mem leak in intel_sdvo_write_cmd() Message-ID: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 Cc: Daniel Vetter , Jesse Barnes , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org 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 --- drivers/gpu/drm/i915/intel_sdvo.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) note: compile tested only due to lack of hardware. 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);