From patchwork Thu Jun 12 20:53:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 359329 X-Patchwork-Delegate: jagannadh.teki@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 7334E140076 for ; Fri, 13 Jun 2014 06:54:20 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EFEAD4B925; Thu, 12 Jun 2014 22:54:17 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SHFDWfAG6msl; Thu, 12 Jun 2014 22:54:17 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E90774B92C; Thu, 12 Jun 2014 22:54:13 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 686064B92C for ; Thu, 12 Jun 2014 22:54:10 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Az3WFFEW9m+s for ; Thu, 12 Jun 2014 22:54:07 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.10]) by theia.denx.de (Postfix) with ESMTPS id 1418E4B925 for ; Thu, 12 Jun 2014 22:54:03 +0200 (CEST) Received: from frontend1.mail.m-online.net (frontend1.mail.intern.m-online.net [192.168.8.180]) by mail-out.m-online.net (Postfix) with ESMTP id 3gqHNp2ZWVz3hhYW; Thu, 12 Jun 2014 22:54:02 +0200 (CEST) X-Auth-Info: Gc99JiDzw7v5lH3eBiwHnDABgmDdeUxlwPLxSWHaoj4= Received: from chi.lan (unknown [195.140.253.167]) by smtp-auth.mnet-online.de (Postfix) with ESMTPA id 3gqHNp1VdLzbbbr; Thu, 12 Jun 2014 22:54:02 +0200 (CEST) From: Marek Vasut To: u-boot@lists.denx.de Date: Thu, 12 Jun 2014 22:53:58 +0200 Message-Id: <1402606438-7602-1-git-send-email-marex@denx.de> X-Mailer: git-send-email 2.0.0.rc2 Cc: Marek Vasut , Michal Simek , Jagannadha Sutradharudu Teki Subject: [U-Boot] [PATCH] sf: Stop leaking memory X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de It's usually a common pattern to free() the memory that we allocated. Implement this here to stop leaking memory. Also, add a debug output when BAR configuration fails to follow suit. Signed-off-by: Marek Vasut Cc: Michal Simek Cc: Jagannadha Sutradharudu Teki --- drivers/mtd/spi/sf_ops.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) NOTE: I think we can do without the memory allocation here altogether. Is there any upper limit on the number of dummy bytes that can go with a SF command? If so, we can just allocate that buffer on a stack and be done with it. diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c index ef91b92..29a7867 100644 --- a/drivers/mtd/spi/sf_ops.c +++ b/drivers/mtd/spi/sf_ops.c @@ -398,8 +398,10 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset, #endif #ifdef CONFIG_SPI_FLASH_BAR bank_sel = spi_flash_bank(flash, read_addr); - if (bank_sel < 0) - return ret; + if (bank_sel < 0) { + debug("SF: bank select failed\n"); + break; + } #endif remain_len = ((SPI_FLASH_16MB_BOUN << flash->shift) * (bank_sel + 1)) - offset; @@ -421,6 +423,7 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset, data += read_len; } + free(cmd); return ret; }