From 107d511bdc15c8daabe1e8b7f7aab095eca8c740 Mon Sep 17 00:00:00 2001 From: Sham Muthayyan Date: Mon, 30 Sep 2019 18:02:20 +0530 Subject: [PATCH] Revert "ipq807x: fat: Fix overflow issue" This reverts commit 8791ff3dabaad123006cb97b041b05ff79e320e0. Change-Id: I03af0ce35aa2df9e381b98c3842e4b88fbd35e1d Signed-off-by: Sham Muthayyan --- board/qca/arm/common/crashdump.c | 2 +- fs/fat/fat_write.c | 30 ++++++++++++------------------ include/fat.h | 1 - 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/board/qca/arm/common/crashdump.c b/board/qca/arm/common/crashdump.c index 355d46aa7a..ca7598f428 100644 --- a/board/qca/arm/common/crashdump.c +++ b/board/qca/arm/common/crashdump.c @@ -377,7 +377,7 @@ static int dump_wlan_segments(struct dumpinfo_t *dumpinfo, int indx) if (cur_type == QCA_WDT_LOG_DUMP_TYPE_WLAN_MOD_INFO) { snprintf(wlan_segment_name, sizeof(wlan_segment_name), - "MOD_INFO.txt"); + "MODULE_INFO.txt"); wlan_tlv_size = *(uint32_t *)(uintptr_t)tlv_info.size; } else { snprintf(wlan_segment_name, diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 56ee76760e..d087f6ca9e 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -806,25 +806,21 @@ static void fill_dentry(fsdata *mydata, dir_entry *dentptr, static int check_overflow(fsdata *mydata, __u32 clustnum, loff_t size) { __u32 startsect, sect_num, offset; - __u32 total_clusters = 0; - total_clusters = ((total_sector - mydata->rootdir_sect - - mydata->rootdir_size) / - mydata->clust_size) - 3; - - /* the last sectors could be orphaned and not belong to any cluster */ - if (clustnum >= total_clusters) { - return -1; - } else if (!clustnum) { + if (clustnum > 0) { + startsect = mydata->data_begin + + clustnum * mydata->clust_size; + } else { startsect = mydata->rootdir_sect; - sect_num = div_u64_rem(size, mydata->sect_size, &offset); - - if (offset != 0) - sect_num++; - if (startsect + sect_num > total_sector) - return -1; } + sect_num = div_u64_rem(size, mydata->sect_size, &offset); + + if (offset != 0) + sect_num++; + + if (startsect + sect_num > total_sector) + return -1; return 0; } @@ -1007,9 +1003,8 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, if (mydata->fatsize == 32) { mydata->data_begin = mydata->rootdir_sect - (mydata->clust_size * 2); - mydata->rootdir_size = 0; } else { - __u16 rootdir_size; + int rootdir_size; rootdir_size = ((bs.dir_entries[1] * (int)256 + bs.dir_entries[0]) * @@ -1018,7 +1013,6 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, mydata->data_begin = mydata->rootdir_sect + rootdir_size - (mydata->clust_size * 2); - mydata->rootdir_size = rootdir_size; } mydata->fatbufnum = -1; diff --git a/include/fat.h b/include/fat.h index 6016b55019..3038bd7e4f 100644 --- a/include/fat.h +++ b/include/fat.h @@ -174,7 +174,6 @@ typedef struct { __u16 clust_size; /* Size of clusters in sectors */ int data_begin; /* The sector of the first cluster, can be negative */ int fatbufnum; /* Used by get_fatent, init to -1 */ - __u16 rootdir_size; /* total sectors in rootdir */ } fsdata; typedef int (file_detectfs_func)(void);