From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lukasz Majewski Date: Thu, 17 Sep 2015 16:44:45 +0200 Subject: [U-Boot] [PATCH] FIX: fat: Provide correct return code from disk_{read|write} to upper layers In-Reply-To: <20150909090257.4065b64f@amdc2363> References: <1440769821-24005-2-git-send-email-l.majewski@samsung.com> <1441282899-13569-1-git-send-email-l.majewski@samsung.com> <20150909090257.4065b64f@amdc2363> Message-ID: <20150917164445.23884479@amdc2363> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi Tom,, > Hi, > > > It is very common that FAT code is using following pattern: > > if (disk_{read|write}() < 0) > > return -1; > > > > Up till now the above code was dead, since disk_{read|write) could > > only return value >= 0. > > As a result some errors from medium layer (i.e. eMMC/SD) were not > > caught. > > > > The above behavior was caused by block_{read|write|erase} declared > > at struct block_dev_desc (@part.h). It returns unsigned long, where > > 0 indicates error and > 0 indicates that medium operation was > > correct. > > > > This patch as error regards 0 returned from block_{read|write|erase} > > when nr_blocks is grater than zero. Read/Write operation with > > nr_blocks=0 should return 0 and hence is not considered as an error. > > > > Signed-off-by: Lukasz Majewski > > Are there any more questions regarding this patch? I'd be more than > happy if it would be added to v2015.10 :-). Gentle ping :-) > > > > > Test HW: Odroid XU3 - Exynos 5433 > > --- > > fs/fat/fat.c | 11 +++++++++-- > > fs/fat/fat_write.c | 11 +++++++++-- > > 2 files changed, 18 insertions(+), 4 deletions(-) > > > > diff --git a/fs/fat/fat.c b/fs/fat/fat.c > > index bccc3e3..d743014 100644 > > --- a/fs/fat/fat.c > > +++ b/fs/fat/fat.c > > @@ -45,11 +45,18 @@ static disk_partition_t cur_part_info; > > > > static int disk_read(__u32 block, __u32 nr_blocks, void *buf) > > { > > + ulong ret; > > + > > if (!cur_dev || !cur_dev->block_read) > > return -1; > > > > - return cur_dev->block_read(cur_dev->dev, > > - cur_part_info.start + block, nr_blocks, > > buf); > > + ret = cur_dev->block_read(cur_dev->dev, > > + cur_part_info.start + block, > > nr_blocks, buf); + > > + if (nr_blocks && ret == 0) > > + return -1; > > + > > + return ret; > > } > > > > int fat_set_blk_dev(block_dev_desc_t *dev_desc, disk_partition_t > > *info) diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c > > index 98b88ad..adb6940 100644 > > --- a/fs/fat/fat_write.c > > +++ b/fs/fat/fat_write.c > > @@ -30,6 +30,8 @@ static void uppercase(char *str, int len) > > static int total_sector; > > static int disk_write(__u32 block, __u32 nr_blocks, void *buf) > > { > > + ulong ret; > > + > > if (!cur_dev || !cur_dev->block_write) > > return -1; > > > > @@ -39,8 +41,13 @@ static int disk_write(__u32 block, __u32 > > nr_blocks, void *buf) return -1; > > } > > > > - return cur_dev->block_write(cur_dev->dev, > > - cur_part_info.start + block, > > nr_blocks, buf); > > + ret = cur_dev->block_write(cur_dev->dev, > > + cur_part_info.start + block, > > + nr_blocks, buf); > > + if (nr_blocks && ret == 0) > > + return -1; > > + > > + return ret; > > } > > > > /* > > > -- Best regards, Lukasz Majewski Samsung R&D Institute Poland (SRPOL) | Linux Platform Group