From patchwork Sun Sep 1 05:51:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11125091 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0BE9314F7 for ; Sun, 1 Sep 2019 05:52:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D43A721897 for ; Sun, 1 Sep 2019 05:52:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=aol.com header.i=@aol.com header.b="bkiQ3g/5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725996AbfIAFwJ (ORCPT ); Sun, 1 Sep 2019 01:52:09 -0400 Received: from sonic306-19.consmr.mail.gq1.yahoo.com ([98.137.68.82]:39869 "EHLO sonic306-19.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725936AbfIAFwJ (ORCPT ); Sun, 1 Sep 2019 01:52:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1567317128; bh=EsqxrbX/MPoMpn28nrMtpulaUGerDCF/NdboPa4sW90=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=bkiQ3g/5Qz3erwRBQhlX46Jdu9sYuCheycRpl61dYaKQz7EYEB8EVYWR5Ti+kYZ8YHpKjC7rzkk5IqmfWDPPHKhKUqoxWXQjsZHgguQAs2Xojc6uk7r0gamfHPe9mmFvDBdZxf75PaGALaSyVOEy9pesv0H0lz3TR1Y358rme9NU4o0iOD1XqwO8c1ZS9RT7WMPDvC32quuUFW2zdYqXIeENYSp4S5JjYI0g7mkme9eMkzVdVARkTR2PG+uQN1PRYmDPbY96hssk9CnN9s+DPZupSl11k+1r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CLNLMwRfAwsPhzw8K6amZo0VGQKGw0VOm5HlErUD0MCcCPcRj Y1pVeu9h9ZvrpPqilrCHqmuMaVbKSkz5Yd1OPyAyuJ1erUNuToeCWyh8JbL1ydQ3P318KWPZkqD3 GgCh0nvwCutD.eSBdkivLpEBozzhDN7gcndC0c0qb6.nmfst6mUe72bD5USfj.KI9Wc4.FOtDN9b M8CnokyE_RilCBZEIyhI_tglFENxWyf7Ul4RpcgurikJK19RIVYV.fqwkPteZhMKyOxyleFsiF.q PmBhfWKKWQ0IcHufwMaSoamb6g9fRhBfA9VV2NsU- Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.gq1.yahoo.com with HTTP; Sun, 1 Sep 2019 05:52:08 +0000 Received: by smtp406.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 426e3b5ec1af9e36f409445c51071a70; Sun, 01 Sep 2019 05:52:03 +0000 (UTC) From: Gao Xiang To: Christoph Hellwig , Chao Yu , Greg Kroah-Hartman Cc: linux-fsdevel@vger.kernel.org, devel@driverdev.osuosl.org, linux-erofs@lists.ozlabs.org, Chao Yu , Gao Xiang Subject: [PATCH 03/21] erofs: some macros are much more readable as a function Date: Sun, 1 Sep 2019 13:51:12 +0800 Message-Id: <20190901055130.30572-4-hsiangkao@aol.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190901055130.30572-1-hsiangkao@aol.com> References: <20190802125347.166018-1-gaoxiang25@huawei.com> <20190901055130.30572-1-hsiangkao@aol.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Gao Xiang As Christoph suggested [1], these macros are much more readable as a function. [1] https://lore.kernel.org/r/20190829095954.GB20598@infradead.org/ Reported-by: Christoph Hellwig Signed-off-by: Gao Xiang --- fs/erofs/erofs_fs.h | 22 ++++++++++++++-------- fs/erofs/inode.c | 4 ++-- fs/erofs/xattr.c | 2 +- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/fs/erofs/erofs_fs.h b/fs/erofs/erofs_fs.h index d1f152a3670a..c1220b0f26e0 100644 --- a/fs/erofs/erofs_fs.h +++ b/fs/erofs/erofs_fs.h @@ -171,16 +171,22 @@ struct erofs_xattr_entry { char e_name[0]; /* attribute name */ } __packed; -#define ondisk_xattr_ibody_size(count) ({\ - u32 __count = le16_to_cpu(count); \ - ((__count) == 0) ? 0 : \ - sizeof(struct erofs_xattr_ibody_header) + \ - sizeof(__u32) * ((__count) - 1); }) +static inline unsigned int erofs_xattr_ibody_size(__le16 i_xattr_icount) +{ + if (!i_xattr_icount) + return 0; + + return sizeof(struct erofs_xattr_ibody_header) + + sizeof(__u32) * (le16_to_cpu(i_xattr_icount) - 1); +} #define EROFS_XATTR_ALIGN(size) round_up(size, sizeof(struct erofs_xattr_entry)) -#define EROFS_XATTR_ENTRY_SIZE(entry) EROFS_XATTR_ALIGN( \ - sizeof(struct erofs_xattr_entry) + \ - (entry)->e_name_len + le16_to_cpu((entry)->e_value_size)) + +static inline unsigned int erofs_xattr_entry_size(struct erofs_xattr_entry *e) +{ + return EROFS_XATTR_ALIGN(sizeof(struct erofs_xattr_entry) + + e->e_name_len + le16_to_cpu(e->e_value_size)); +} /* available compression algorithm types */ enum { diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index 8a0574530a0a..3fc4f764b387 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -29,7 +29,7 @@ static int read_inode(struct inode *inode, void *data) struct erofs_inode_v2 *v2 = data; vi->inode_isize = sizeof(struct erofs_inode_v2); - vi->xattr_isize = ondisk_xattr_ibody_size(v2->i_xattr_icount); + vi->xattr_isize = erofs_xattr_ibody_size(v2->i_xattr_icount); inode->i_mode = le16_to_cpu(v2->i_mode); if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || @@ -62,7 +62,7 @@ static int read_inode(struct inode *inode, void *data) struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb); vi->inode_isize = sizeof(struct erofs_inode_v1); - vi->xattr_isize = ondisk_xattr_ibody_size(v1->i_xattr_icount); + vi->xattr_isize = erofs_xattr_ibody_size(v1->i_xattr_icount); inode->i_mode = le16_to_cpu(v1->i_mode); if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index d80f61dde72f..620cbc15f4d0 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -231,7 +231,7 @@ static int xattr_foreach(struct xattr_iter *it, */ entry = *(struct erofs_xattr_entry *)(it->kaddr + it->ofs); if (tlimit) { - unsigned int entry_sz = EROFS_XATTR_ENTRY_SIZE(&entry); + unsigned int entry_sz = erofs_xattr_entry_size(&entry); /* xattr on-disk corruption: xattr entry beyond xattr_isize */ if (*tlimit < entry_sz) {