From patchwork Wed Jul 24 09:55:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Wu X-Patchwork-Id: 261401 X-Patchwork-Delegate: trini@ti.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 E059E2C0096 for ; Wed, 24 Jul 2013 19:59:12 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A01864A023; Wed, 24 Jul 2013 11:59:11 +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 JBln7duxljtN; Wed, 24 Jul 2013 11:59:11 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EF48C4A01B; Wed, 24 Jul 2013 11:59:09 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B416C4A01B for ; Wed, 24 Jul 2013 11:59:06 +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 yaSzIzc+asg3 for ; Wed, 24 Jul 2013 11:59:01 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 BL_NJABL=ERR(-1.5) (only DNSBL check requested) Received: from nasmtp02.atmel.com (nasmtp02.atmel.com [204.2.163.16]) by theia.denx.de (Postfix) with ESMTPS id 3140B4A019 for ; Wed, 24 Jul 2013 11:58:53 +0200 (CEST) Received: from apsmtp01.atmel.com (10.168.254.30) by sjoedg01.corp.atmel.com (10.64.253.30) with Microsoft SMTP Server (TLS) id 14.2.342.3; Wed, 24 Jul 2013 03:04:50 -0700 Received: from shaarm01.corp.atmel.com (10.168.254.13) by apsmtp01.corp.atmel.com (10.168.254.30) with Microsoft SMTP Server id 14.2.342.3; Wed, 24 Jul 2013 18:00:40 +0800 From: Josh Wu To: Date: Wed, 24 Jul 2013 17:55:30 +0800 Message-ID: <1374659730-2634-1-git-send-email-josh.wu@atmel.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 Cc: RCommandeur@clb.nl, u-boot@lists.denx.de, Mats.Karrman@tritech.se, trini@ti.com Subject: [U-Boot] [PATCH] fs: fat: don't call disk_write with zero sector num 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: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de In the set_cluster() function, it will convert the buffer size to sector numbers. Then call disk_write() to write by sector. For remaining buffer, the size is less than a sector, call disk_write() again to write them in one sector. But if the total buffer size is less then one sector, the original code will call disk_write() with zero sector number. It is unnecessary. So this patch fix this. Now it will not call disk_write() if total buffer size is less than one sector. Signed-off-by: Josh Wu --- fs/fat/fat_write.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index fd07240..a05327c 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -568,9 +568,11 @@ set_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, debug("clustnum: %d, startsect: %d\n", clustnum, startsect); - if (disk_write(startsect, size / mydata->sect_size, buffer) < 0) { - debug("Error writing data\n"); - return -1; + if ((size / mydata->sect_size) > 0) { + if (disk_write(startsect, size / mydata->sect_size, buffer) < 0) { + debug("Error writing data\n"); + return -1; + } } if (size % mydata->sect_size) {