From patchwork Mon Jan 9 19:12:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabian Frederick X-Patchwork-Id: 9505781 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 018B96071A for ; Mon, 9 Jan 2017 19:13:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0B2D2852B for ; Mon, 9 Jan 2017 19:13:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4D0028532; Mon, 9 Jan 2017 19:13:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AA852852B for ; Mon, 9 Jan 2017 19:13:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1423265AbdAITNi (ORCPT ); Mon, 9 Jan 2017 14:13:38 -0500 Received: from mailrelay103.isp.belgacom.be ([195.238.20.130]:9700 "EHLO mailrelay103.isp.belgacom.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935226AbdAITMR (ORCPT ); Mon, 9 Jan 2017 14:12:17 -0500 X-Belgacom-Dynamic: yes X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2B6CgCm33NY/2ZisVtdHgYMgmxOAQEBA?= =?us-ascii?q?QEfQIErjkmRWgGScYIPggqGIgKBZkISAQIBAQEBAQEBYyiEaQYnLyMQGTg5HgY?= =?us-ascii?q?TiGMRsXg6hBCGDQEBAQcohkWPDQWbHJFADZBcklUmCCmBJBkYhGccgWA9NYYrK?= =?us-ascii?q?4IQAQEB?= X-IPAS-Result: =?us-ascii?q?A2B6CgCm33NY/2ZisVtdHgYMgmxOAQEBAQEfQIErjkmRWgG?= =?us-ascii?q?ScYIPggqGIgKBZkISAQIBAQEBAQEBYyiEaQYnLyMQGTg5HgYTiGMRsXg6hBCGD?= =?us-ascii?q?QEBAQcohkWPDQWbHJFADZBcklUmCCmBJBkYhGccgWA9NYYrK4IQAQEB?= Received: from 102.98-177-91.adsl-dyn.isp.belgacom.be (HELO localhost.localdomain) ([91.177.98.102]) by relay.skynet.be with ESMTP; 09 Jan 2017 20:12:14 +0100 From: Fabian Frederick To: Andrew Morton Cc: Jan Kara , Alexander Viro , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, fabf@skynet.be Subject: [PATCH V2 2/7 linux-next] fs/affs: add validation block function Date: Mon, 9 Jan 2017 20:12:03 +0100 Message-Id: <20170109191208.6085-3-fabf@skynet.be> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170109191208.6085-1-fabf@skynet.be> References: <20170109191208.6085-1-fabf@skynet.be> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP avoid repeating 4 times the same calculation. Signed-off-by: Fabian Frederick --- fs/affs/affs.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/affs/affs.h b/fs/affs/affs.h index 899256b..efe6839 100644 --- a/fs/affs/affs.h +++ b/fs/affs/affs.h @@ -212,6 +212,12 @@ extern const struct address_space_operations affs_aops_ofs; extern const struct dentry_operations affs_dentry_operations; extern const struct dentry_operations affs_intl_dentry_operations; +static inline bool affs_validblock(struct super_block *sb, int block) +{ + return(block >= AFFS_SB(sb)->s_reserved && + block < AFFS_SB(sb)->s_partition_size); +} + static inline void affs_set_blocksize(struct super_block *sb, int size) { @@ -221,7 +227,7 @@ static inline struct buffer_head * affs_bread(struct super_block *sb, int block) { pr_debug("%s: %d\n", __func__, block); - if (block >= AFFS_SB(sb)->s_reserved && block < AFFS_SB(sb)->s_partition_size) + if (affs_validblock(sb, block)) return sb_bread(sb, block); return NULL; } @@ -229,7 +235,7 @@ static inline struct buffer_head * affs_getblk(struct super_block *sb, int block) { pr_debug("%s: %d\n", __func__, block); - if (block >= AFFS_SB(sb)->s_reserved && block < AFFS_SB(sb)->s_partition_size) + if (affs_validblock(sb, block)) return sb_getblk(sb, block); return NULL; } @@ -238,7 +244,7 @@ affs_getzeroblk(struct super_block *sb, int block) { struct buffer_head *bh; pr_debug("%s: %d\n", __func__, block); - if (block >= AFFS_SB(sb)->s_reserved && block < AFFS_SB(sb)->s_partition_size) { + if (affs_validblock(sb, block)) { bh = sb_getblk(sb, block); lock_buffer(bh); memset(bh->b_data, 0 , sb->s_blocksize); @@ -253,7 +259,7 @@ affs_getemptyblk(struct super_block *sb, int block) { struct buffer_head *bh; pr_debug("%s: %d\n", __func__, block); - if (block >= AFFS_SB(sb)->s_reserved && block < AFFS_SB(sb)->s_partition_size) { + if (affs_validblock(sb, block)) { bh = sb_getblk(sb, block); wait_on_buffer(bh); set_buffer_uptodate(bh);