From: Timothy Shimmin <tes@sgi.com>
To: lachlan@sgi.com
Cc: xfs-oss <xfs@oss.sgi.com>
Subject: Re: [PATCH] Fix off by one error in page_region_mask()
Date: Mon, 08 Dec 2008 15:42:04 +1100 [thread overview]
Message-ID: <493CA59C.302@sgi.com> (raw)
In-Reply-To: <49378B60.1060603@sgi.com>
Lachlan McIlroy wrote:
> final is calculated to be the last bit to set (ie inclusive) but when we
> do the mask shifting final really needs to be first bit not to set.
>
> For example if first and final are both bit 0 (ie only first bit to be set)
> then mask is completely shifted and becomes all zeroes.
>
> Or if first is 0 and final is 63 then the mask is shifted one bit when it
> shouldn't be shifted at all.
>
> --- xfs-fix.orig/fs/xfs/linux-2.6/xfs_buf.c
> +++ xfs-fix/fs/xfs/linux-2.6/xfs_buf.c
> @@ -129,15 +129,17 @@ page_region_mask(
> int first, final;
>
> first = BTOPR(offset);
> - final = BTOPRT(offset + length - 1);
> - first = min(first, final);
> + final = BTOPRT(offset + length);
> +
> + if (first >= final)
> + return 0UL;
>
> mask = ~0UL;
> mask <<= BITS_PER_LONG - (final - first);
> mask >>= BITS_PER_LONG - (final);
>
> ASSERT(offset + length <= PAGE_CACHE_SIZE);
> - ASSERT((final - first) < BITS_PER_LONG && (final - first) >= 0);
> + ASSERT((final - first) <= BITS_PER_LONG && (final - first) > 0);
>
> return mask;
> }
>
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
Gee, I always find these tricky to get right.
I tend to like a userspace version and input various ranges,
such as extremes like you did, and verify it is working.
I kind of like first and final to be inclusive of the range to be set
(not so keen on making final to be first bit not to set -
name doesn't seem so good then).
And if one needs to know the size of the range to use (final - first + 1)
and for 0..final => size = final-0+1 = final+1.
And the thing about min(first, final) and (first >= final),
is interesting - I would have thought final would be expected to be >=
to the first ??
Okay, the other thing that interests me is the use of both BTOPR and BTOPRT
for given offsets.
BTOPR is the typical howmany() implementation, where if you go over
a multiple-boundaries worth then you need another multiple.
I would expect it to have values starting from 1.
So I was thinking typically of BTOPR for sizes and BTOPRT for 0-based offsets.
e.g. given multiple, 512
BTOPR 1..512 => 1, 513..1024 => 2
BTOPRT 0..511 => 0, 512..1023 => 1
So I find the code a bit hard to follow then.
--Tim
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2008-12-08 4:42 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-04 7:48 [PATCH] Fix off by one error in page_region_mask() Lachlan McIlroy
2008-12-04 15:44 ` Eric Sandeen
2008-12-05 0:59 ` Lachlan McIlroy
2008-12-05 4:53 ` Eric Sandeen
2008-12-05 5:06 ` Lachlan McIlroy
2008-12-08 4:42 ` Timothy Shimmin [this message]
2008-12-08 5:16 ` Lachlan McIlroy
2008-12-22 8:53 ` Christoph Hellwig
2008-12-23 0:23 ` Lachlan McIlroy
2009-01-19 6:53 ` Lachlan McIlroy
2009-01-22 22:25 ` Christoph Hellwig
2009-02-15 19:16 ` Christoph Hellwig
2009-02-16 17:14 ` Felix Blyakher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=493CA59C.302@sgi.com \
--to=tes@sgi.com \
--cc=lachlan@sgi.com \
--cc=xfs@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox