From: Roman Zippel The key values are unsigned, so comparing them using the difference doesn't always work. (Problem reported by k_guillaume@libertysurf.fr) Signed-off-by: Roman Zippel Signed-off-by: Andrew Morton --- 25-akpm/fs/hfs/extent.c | 29 ++++++++++++++--------------- 1 files changed, 14 insertions(+), 15 deletions(-) diff -puN fs/hfs/extent.c~hfs-fix-sign-problem-in-hfs_ext_keycmp fs/hfs/extent.c --- 25/fs/hfs/extent.c~hfs-fix-sign-problem-in-hfs_ext_keycmp 2005-03-18 23:43:01.000000000 -0800 +++ 25-akpm/fs/hfs/extent.c 2005-03-18 23:43:01.000000000 -0800 @@ -49,22 +49,21 @@ static void hfs_ext_build_key(hfs_btree_ * This function has no side-effects */ int hfs_ext_keycmp(const btree_key *key1, const btree_key *key2) { - unsigned int tmp; - int retval; + __be32 fnum1, fnum2; + __be16 block1, block2; - tmp = be32_to_cpu(key1->ext.FNum) - be32_to_cpu(key2->ext.FNum); - if (tmp != 0) { - retval = (int)tmp; - } else { - tmp = (unsigned char)key1->ext.FkType - (unsigned char)key2->ext.FkType; - if (tmp != 0) { - retval = (int)tmp; - } else { - retval = (int)(be16_to_cpu(key1->ext.FABN) - - be16_to_cpu(key2->ext.FABN)); - } - } - return retval; + fnum1 = key1->ext.FNum; + fnum2 = key2->ext.FNum; + if (fnum1 != fnum2) + return be32_to_cpu(fnum1) < be32_to_cpu(fnum2) ? -1 : 1; + if (key1->ext.FkType != key2->ext.FkType) + return key1->ext.FkType < key2->ext.FkType ? -1 : 1; + + block1 = key1->ext.FABN; + block2 = key2->ext.FABN; + if (block1 == block2) + return 0; + return be16_to_cpu(block1) < be16_to_cpu(block2) ? -1 : 1; } /* _