From patchwork Thu Jan 17 06:52:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chee, Tien Fong" X-Patchwork-Id: 1026420 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=intel.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43gFBg3R1Gz9sD9 for ; Thu, 17 Jan 2019 17:52:43 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 38937C2207B; Thu, 17 Jan 2019 06:52:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 4D60DC21C4A; Thu, 17 Jan 2019 06:52:38 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B72F3C21C4A; Thu, 17 Jan 2019 06:52:37 +0000 (UTC) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lists.denx.de (Postfix) with ESMTPS id E4584C21C29 for ; Thu, 17 Jan 2019 06:52:36 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jan 2019 22:52:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,488,1539673200"; d="scan'208";a="126521343" Received: from pg-iccf0298.altera.com ([10.104.2.51]) by FMSMGA003.fm.intel.com with ESMTP; 16 Jan 2019 22:52:31 -0800 From: tien.fong.chee@intel.com To: u-boot@lists.denx.de Date: Thu, 17 Jan 2019 14:52:27 +0800 Message-Id: <1547707948-21484-1-git-send-email-tien.fong.chee@intel.com> X-Mailer: git-send-email 1.7.7.4 Cc: Marek Vasut , Tom Rini , Tien Fong Chee , Ching Liang See , Heinrich Schuchardt , Stefan Agner <"stefan.ag..."@toradex.com>, Alexander Graf , Westergteen Dalon Subject: [U-Boot] [PATCH 1/2] fs: fat: dynamically allocate memory for temporary buffer X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Stefan Agner Drop the statically allocated get_contents_vfatname_block and dynamically allocate a buffer only if required. This saves 64KiB of memory. Signed-off-by: Stefan Agner Signed-off-by: Tien Fong Chee --- fs/fat/fat.c | 19 +++++++++++++------ 1 files changed, 13 insertions(+), 6 deletions(-) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 8803fb4..aa4636d 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -307,9 +307,6 @@ get_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size) * into 'buffer'. * Update the number of bytes read in *gotsize or return -1 on fatal errors. */ -__u8 get_contents_vfatname_block[MAX_CLUSTSIZE] - __aligned(ARCH_DMA_MINALIGN); - static int get_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos, __u8 *buffer, loff_t maxsize, loff_t *gotsize) { @@ -320,7 +317,7 @@ static int get_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos, loff_t actsize; *gotsize = 0; - debug("Filesize: %llu bytes\n", filesize); + debug("Filesize: %llu bytes, starting at pos %llu\n", filesize, pos); if (pos >= filesize) { debug("Read position past EOF: %llu\n", pos); @@ -352,15 +349,25 @@ static int get_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos, /* align to beginning of next cluster if any */ if (pos) { + __u8 *tmp_buffer; + + tmp_buffer = malloc_cache_aligned(MAX_CLUSTSIZE); + if (!tmp_buffer) { + debug("Error: allocating buffer\n"); + return -ENOMEM; + } + actsize = min(filesize, (loff_t)bytesperclust); - if (get_cluster(mydata, curclust, get_contents_vfatname_block, + if (get_cluster(mydata, curclust, tmp_buffer, (int)actsize) != 0) { printf("Error reading cluster\n"); + free(tmp_buffer); return -1; } filesize -= actsize; actsize -= pos; - memcpy(buffer, get_contents_vfatname_block + pos, actsize); + memcpy(buffer, tmp_buffer + pos, actsize); + free(tmp_buffer); *gotsize += actsize; if (!filesize) return 0; From patchwork Thu Jan 17 06:52:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chee, Tien Fong" X-Patchwork-Id: 1026421 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=intel.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43gFCF4g63z9sD9 for ; Thu, 17 Jan 2019 17:53:13 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 47843C21E75; Thu, 17 Jan 2019 06:52:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 0CCCEC220CC; Thu, 17 Jan 2019 06:52:47 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 91D97C22042; Thu, 17 Jan 2019 06:52:42 +0000 (UTC) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lists.denx.de (Postfix) with ESMTPS id 71520C21E75 for ; Thu, 17 Jan 2019 06:52:38 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jan 2019 22:52:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,488,1539673200"; d="scan'208";a="126521351" Received: from pg-iccf0298.altera.com ([10.104.2.51]) by FMSMGA003.fm.intel.com with ESMTP; 16 Jan 2019 22:52:35 -0800 From: tien.fong.chee@intel.com To: u-boot@lists.denx.de Date: Thu, 17 Jan 2019 14:52:28 +0800 Message-Id: <1547707948-21484-2-git-send-email-tien.fong.chee@intel.com> X-Mailer: git-send-email 1.7.7.4 In-Reply-To: <1547707948-21484-1-git-send-email-tien.fong.chee@intel.com> References: <1547707948-21484-1-git-send-email-tien.fong.chee@intel.com> Cc: Marek Vasut , Tom Rini , Tien Fong Chee , Ching Liang See , Heinrich Schuchardt , Stefan Agner <"stefan.ag..."@toradex.com>, Alexander Graf , Westergteen Dalon Subject: [U-Boot] [PATCH 2/2] fs: fat: Reduce default max clustersize 64KiB from malloc pool X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Tien Fong Chee Release cluster block immediately when no longer use would help to reduce 64KiB memory allocated to the memory pool. Signed-off-by: Tien Fong Chee --- fs/fat/fat.c | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index aa4636d..5574620 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -1153,12 +1153,19 @@ int file_fat_read_at(const char *filename, loff_t pos, void *buffer, goto out_free_both; debug("reading %s at pos %llu\n", filename, pos); - ret = get_contents(&fsdata, itr->dent, pos, buffer, maxsize, actread); + + /* For saving default max clustersize memory allocated to malloc pool */ + dir_entry *dentptr = itr->dent; + + free(itr); + + ret = get_contents(&fsdata, dentptr, pos, buffer, maxsize, actread); out_free_both: free(fsdata.fatbuf); out_free_itr: - free(itr); + if (!itr) + free(itr); return ret; }