From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752258AbcGBNxl (ORCPT ); Sat, 2 Jul 2016 09:53:41 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:34754 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751409AbcGBNxk (ORCPT ); Sat, 2 Jul 2016 09:53:40 -0400 Date: Sat, 2 Jul 2016 14:34:43 +0100 From: Salah Triki To: Luis de Bethencourt Cc: Salah Triki , akpm@linux-foundation.org, viro@zeniv.linux.org.uk, mhocko@suse.com, vdavydov@virtuozzo.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/4] fs: befs: Remove redundant validation from befs_find_brun_direct Message-ID: <20160702133443.GB3817@pc> References: <9859a616787673d2f36ce21d4aa0220637c55001.1467446561.git.salah.triki@gmail.com> <5777A7AA.4020500@osg.samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5777A7AA.4020500@osg.samsung.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jul 02, 2016 at 12:38:18PM +0100, Luis de Bethencourt wrote: > On 02/07/16 09:05, Salah Triki wrote: > > The only caller of befs_find_brun_direct is befs_fblock2brun, which > > already validates that the block is within the range of direct blocks. > > So remove the duplicate validation. > > > > Signed-off-by: Salah Triki > > --- > > fs/befs/datastream.c | 8 -------- > > 1 file changed, 8 deletions(-) > > > > diff --git a/fs/befs/datastream.c b/fs/befs/datastream.c > > index 26cc417..e224b9a 100644 > > --- a/fs/befs/datastream.c > > +++ b/fs/befs/datastream.c > > @@ -249,17 +249,9 @@ befs_find_brun_direct(struct super_block *sb, const befs_data_stream *data, > > int i; > > const befs_block_run *array = data->direct; > > befs_blocknr_t sum; > > - befs_blocknr_t max_block = > > - data->max_direct_range >> BEFS_SB(sb)->block_shift; > > > > befs_debug(sb, "---> %s, find %lu", __func__, (unsigned long)blockno); > > > > - if (blockno > max_block) { > > - befs_error(sb, "%s passed block outside of direct region", > > - __func__); > > - return BEFS_ERR; > > - } > > - > > for (i = 0, sum = 0; i < BEFS_NUM_DIRECT_BLOCKS; > > sum += array[i].len, i++) { > > if (blockno >= sum && blockno < sum + (array[i].len)) { > > > > Hi Salah, > > These aren't the same check though. If we ignore the BEFS_SB(sb)->block_shift just to > comparing them, we can consider the checks to be the following. > > In befs_fblock2brun(): > if (fblock < data->max_direct_range) > > In befs_find_brun_direct(): > if (fblock > data->max_direct_range) > > Notice how one checks if the block is past the range, and the other checks if it isn't > before it. > > They also looked similar to me the first time I saw them and I had to double-check :) > > Thanks, > Luis > > the two checks could not be evaluated to true at the same time, and since befs_find_brun_direct is called only when the first check is passed, the second check will be always evaluated to false. So I think the second check is useless, am I right ? Salah