From patchwork Wed Jul 13 20:58:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesper Juhl X-Patchwork-Id: 973342 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p6DKwIPu028532 for ; Wed, 13 Jul 2011 20:58:18 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751794Ab1GMU6Q (ORCPT ); Wed, 13 Jul 2011 16:58:16 -0400 Received: from swampdragon.chaosbits.net ([90.184.90.115]:29226 "EHLO swampdragon.chaosbits.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751630Ab1GMU6P (ORCPT ); Wed, 13 Jul 2011 16:58:15 -0400 Received: by swampdragon.chaosbits.net (Postfix, from userid 1000) id 0146C9403E; Wed, 13 Jul 2011 22:58:13 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by swampdragon.chaosbits.net (Postfix) with ESMTP id F1F4E9403B; Wed, 13 Jul 2011 22:58:13 +0200 (CEST) Date: Wed, 13 Jul 2011 22:58:13 +0200 (CEST) From: Jesper Juhl To: Mauro Carvalho Chehab cc: Devin Heitmueller , Andreas Oberritter , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] media, Micronas dvb-t: Fix mem leaks, don't needlessly zero mem, fix spelling Message-ID: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 13 Jul 2011 20:58:18 +0000 (UTC) In drivers/media/dvb/frontends/drxd_hard.c::load_firmware() I see 3 small issues: 1) When the 'fw' variable goes out of scope we'll leak the memory allocated to it by request_firmware() by neglecting to call release_firmware(). 2) After a successful request_firmware() we allocate fw->size bytes of memory using kzalloc() only to immediately overwrite all that memory with memcpy(), so asking for zeroed memory seems like wasted effort - just use kmalloc(). 3) In one of the error messages "no memory" lacks a space and is written as "nomemory". This patch fixes all 3 issues. Signed-off-by: Jesper Juhl --- drivers/media/dvb/frontends/drxd_hard.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/media/dvb/frontends/drxd_hard.c b/drivers/media/dvb/frontends/drxd_hard.c index f132e49..0266a83 100644 --- a/drivers/media/dvb/frontends/drxd_hard.c +++ b/drivers/media/dvb/frontends/drxd_hard.c @@ -909,14 +909,16 @@ static int load_firmware(struct drxd_state *state, const char *fw_name) return -EIO; } - state->microcode = kzalloc(fw->size, GFP_KERNEL); + state->microcode = kmalloc(fw->size, GFP_KERNEL); if (state->microcode == NULL) { - printk(KERN_ERR "drxd: firmware load failure: nomemory\n"); + release_firmware(fw); + printk(KERN_ERR "drxd: firmware load failure: no memory\n"); return -ENOMEM; } memcpy(state->microcode, fw->data, fw->size); state->microcode_length = fw->size; + release_firmware(fw); return 0; }