From patchwork Fri Jun 8 17:31:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 163834 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 43754B6FAF for ; Sat, 9 Jun 2012 03:33:21 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4ACF82828F; Fri, 8 Jun 2012 19:32:51 +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 ddbUSaWQyhhR; Fri, 8 Jun 2012 19:32:51 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D86D028290; Fri, 8 Jun 2012 19:32:20 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 438602823F for ; Fri, 8 Jun 2012 19:32:14 +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 AImIqdMYdkaN for ; Fri, 8 Jun 2012 19:32:13 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.10]) by theia.denx.de (Postfix) with ESMTPS id 6429C2824A for ; Fri, 8 Jun 2012 19:32:04 +0200 (CEST) Received: from frontend1.mail.m-online.net (frontend1.mail.intern.m-online.net [192.168.8.180]) by mail-out.m-online.net (Postfix) with ESMTP id 3W89fY6dMsz3hhc2; Fri, 8 Jun 2012 19:32:05 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.8.164]) by mail.m-online.net (Postfix) with ESMTP id 3W89fX3Kzqz4KK7D; Fri, 8 Jun 2012 19:32:04 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from smtp-auth.mnet-online.de ([192.168.8.180]) by localhost (dynscan1.mail.m-online.net [192.168.8.164]) (amavisd-new, port 10024) with ESMTP id 1+Wc+iQDLd5L; Fri, 8 Jun 2012 19:32:04 +0200 (CEST) Received: from mashiro.lan (unknown [195.140.253.167]) by smtp-auth.mnet-online.de (Postfix) with ESMTPA; Fri, 8 Jun 2012 19:32:03 +0200 (CEST) From: Marek Vasut To: u-boot@lists.denx.de Date: Fri, 8 Jun 2012 19:31:50 +0200 Message-Id: <1339176713-13309-6-git-send-email-marex@denx.de> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1339176713-13309-1-git-send-email-marex@denx.de> References: <1339176713-13309-1-git-send-email-marex@denx.de> Cc: Marek Vasut Subject: [U-Boot] [PATCH 5/8] EXT2: Rework ext2fs_read_symlink() 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: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de * Fix indent * Read inode size only once, as it can be reused Signed-off-by: Marek Vasut Cc: Wolfgang Denk --- fs/ext2/ext2fs.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/fs/ext2/ext2fs.c b/fs/ext2/ext2fs.c index 0d54ae6..22cc9c2 100644 --- a/fs/ext2/ext2fs.c +++ b/fs/ext2/ext2fs.c @@ -458,35 +458,36 @@ static char *ext2fs_read_symlink(struct ext2fs_node *node) char *symlink; struct ext2fs_node *diro = node; int status; + uint32_t size; if (!diro->inode_read) { - status = ext2fs_read_inode (diro->data, diro->ino, - &diro->inode); - if (status == 0) { - return (0); - } - } - symlink = malloc (__le32_to_cpu (diro->inode.size) + 1); - if (!symlink) { - return (0); + status = ext2fs_read_inode(diro->data, diro->ino, &diro->inode); + if (status == 0) + return 0; } - /* If the filesize of the symlink is bigger than - 60 the symlink is stored in a separate block, - otherwise it is stored in the inode. */ - if (__le32_to_cpu (diro->inode.size) <= 60) { - strncpy (symlink, diro->inode.b.symlink, - __le32_to_cpu (diro->inode.size)); + + size = __le32_to_cpu(diro->inode.size); + symlink = malloc(size + 1); + if (!symlink) + return 0; + + /* + * If the filesize of the symlink is bigger than 60 the symlink is + * stored in a separate block, otherwise it is stored in the inode. + */ + if (size <= 60) { + strncpy(symlink, diro->inode.b.symlink, size); } else { - status = ext2fs_read_file (diro, 0, - __le32_to_cpu (diro->inode.size), - symlink); + status = ext2fs_read_file(diro, 0, size, symlink); if (status == 0) { - free (symlink); - return (0); + free(symlink); + return 0; } } - symlink[__le32_to_cpu (diro->inode.size)] = '\0'; - return (symlink); + + symlink[size] = '\0'; + + return symlink; } int ext2fs_find_file1