fs: make the static array to dynamic allocation
PATCH 1/1 fs: make the static array to dynamic allocation
Current fat.c have three 64KB static array, it makes the BSS section larger.
Change the static to dynamic allocation.
--- fs/fat/fat.c | 38 +++++++++++++++++++++++++++++++++++--- 1 files changed, 35 insertions(+), 3 deletions(-)
fs/fat/fat.c +35 -3
@@ -28,6 +28,7 @@#include <common.h> #include <config.h> #include <fat.h> +#include <malloc.h> #include <asm/byteorder.h> #include <part.h>
@@ -65,6 +66,37 @@ int disk_read (__u32 startblock, __u32 getsize, __u8 * bufptr)return -1 ; } +__u8 *get_vfatname_block; +__u8 *get_dentfromdir_block; +__u8 *do_fat_read_block; +static int fat_mem_done =0 ; +static int fat_memory_alloc (void ) +{ +if (fat_mem_done) +return 0 ; + + get_vfatname_block = (__u8 *)malloc (MAX_CLUSTSIZE ); +if (!get_vfatname_block) { +printf ("alloc get_vfatname_block failed\n\r" ); +return -1 ; + } + + get_dentfromdir_block = (__u8 *)malloc (MAX_CLUSTSIZE ); +if (!get_dentfromdir_block) { +printf ("alloc get_dentfromdir_block failed\n\r" ); +return -1 ; + } + + do_fat_read_block = (__u8 *)malloc (MAX_CLUSTSIZE ); +if (!do_fat_read_block) { +printf ("alloc do_fat_read_block failed\n\r" ); +return -1 ; + } + + fat_mem_done =1 ; + +return 0 ; +}int fat_register_device (block_dev_desc_t *dev_desc,int part_no)
@@ -72,6 +104,9 @@ fat_register_device(block_dev_desc_t *dev_desc, int part_no)unsigned char buffer[SECTOR_SIZE ];disk_partition_t info; +if (fat_memory_alloc ()) +printf ("fat memory alloc failed\n\r" ); +if (!dev_desc->block_read)return -1 ; cur_dev = dev_desc;
@@ -435,7 +470,6 @@ slot2str(dir_slot *slotptr, char *l_name, int *idx)* into 'retdent' * Return 0 on success, -1 otherwise. */ -__u8 get_vfatname_block[MAX_CLUSTSIZE ];static int get_vfatname (fsdata *mydata,int curclust,__u8 *cluster,dir_entry *retdent,char *l_name)
@@ -521,7 +555,6 @@ mkcksum(const char *str)* Get the directory entry associated with 'filename' from the directory * starting at 'startsect' */ -__u8 get_dentfromdir_block[MAX_CLUSTSIZE ];static dir_entry *get_dentfromdir (fsdata * mydata,int startsect,char *filename,dir_entry * retdent,int dols)
@@ -727,7 +760,6 @@ read_bootsectandvi(boot_sector *bs, volume_info *volinfo, int *fatsize) } -__u8 do_fat_read_block[MAX_CLUSTSIZE ];/* Block buffer */ long do_fat_read (const char *filename,void *buffer,unsigned long maxsize,int dols)
Signature · 1 line
1.5.4.1
PATCH 1/1 fs: make the static array to dynamic allocation
Quoted 26 lines · Dave Liu
Current
fat.chave three 64KB static array, it makes the BSS section larger.
Change the static to dynamic allocation.Signed-off-by Dave Liu <[email protected]>---
fs/fat/fat.c| 38 +++++++++++++++++++++++++++++++++++---1 files changed, 35 insertions(+), 3 deletions(-)fs/fat/fat.c +1
-0@@ -28,6 +28,7 @@#include <common.h> #include <config.h> #include <fat.h> +#include <malloc.h> #include <asm/byteorder.h> #include <part.h> @@ -65,6 +66,37 @@ int disk_read (__u32 startblock, __u32 getsize, __u8 * bufptr)return -1 ; }
fs/fat/fat.c int disk_read (__u32 startblock, __u32 getsize, · line 79
Quoted 10 lines
fs/fat/fat.c +10
-0+__u8 *get_vfatname_block; +__u8 *get_dentfromdir_block; +__u8 *do_fat_read_block; +static int fat_mem_done =0 ; +static int fat_memory_alloc (void ) +{ +if (fat_mem_done) +return 0 ; + + get_vfatname_block = (__u8 *)malloc (MAX_CLUSTSIZE );
do you really need the cast?
fs/fat/fat.c int disk_read (__u32 startblock, __u32 getsize, __u8 * bufptr) · line 84
Quoted 7 lines
fs/fat/fat.c +6
-0+if (!get_vfatname_block) { +printf ("alloc get_vfatname_block failed\n\r" ); +return -1 ; + } + + get_dentfromdir_block = (__u8 *)malloc (MAX_CLUSTSIZE );
ditto.
fs/fat/fat.c int disk_read (__u32 startblock, __u32 getsize, __u8 * bufptr) · line 90
Quoted 7 lines
fs/fat/fat.c +6
-0+if (!get_dentfromdir_block) { +printf ("alloc get_dentfromdir_block failed\n\r" ); +return -1 ; + } + + do_fat_read_block = (__u8 *)malloc (MAX_CLUSTSIZE );
ditto
fs/fat/fat.c int disk_read (__u32 startblock, __u32 getsize, __u8 * bufptr) · line 99
Quoted 10 lines
fs/fat/fat.c +9
-0+if (!do_fat_read_block) { +printf ("alloc do_fat_read_block failed\n\r" ); +return -1 ; + } + + fat_mem_done =1 ; + +return 0 ; +}
- k
PATCH 1/1 fs: make the static array to dynamic allocation
In reply to Dave LiuQuoted 3 lines · In message <[email protected]> you wrote:
Current
fat.chave three 64KB static array, it makes the BSS section larger.
Change the static to dynamic allocation.
So what's the benefit? BSS size doesn't matter - itr comes for free. It get's initialized automatically.
You add more than 30 lines of code instead, plus a lot of string space, plus a new failure mode (malloc failed) that didn't exist before.
Looks like a pessimizing patch to me, but maybe you just did not describe which problem you are trying to fix?
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Remember, there's a big difference between kneeling down and bending over. - Frank Zappa