public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix off by one error in page_region_mask()
@ 2008-12-04  7:48 Lachlan McIlroy
  2008-12-04 15:44 ` Eric Sandeen
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Lachlan McIlroy @ 2008-12-04  7:48 UTC (permalink / raw)
  To: xfs-oss

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2009-02-16 17:15 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox