Skip to content

Commit 5dd7cbc

Browse files
Kukkonen MikaArtem Bityutskiy
authored andcommitted
UBIFS: avoid unnecessary checks
I have a habit of compiling kernel with EXTRA_CFLAGS="-Wextra -Wno-unused -Wno-sign-compare -Wno-missing-field-initializers" and so fs/ubifs/key.h give lots (~10) of these every time: CC fs/ubifs/tnc_misc.o In file included from fs/ubifs/ubifs.h:1725, from fs/ubifs/tnc_misc.c:30: fs/ubifs/key.h: In function 'key_r5_hash': fs/ubifs/key.h:64: warning: comparison of unsigned expression >= 0 is always true fs/ubifs/key.h: In function 'key_test_hash': fs/ubifs/key.h:81: warning: comparison of unsigned expression >= 0 is always true This patch fixes the warnings. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
1 parent 553dea4 commit 5dd7cbc

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

‎fs/ubifs/key.h‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@
3737
#ifndef __UBIFS_KEY_H__
3838
#define __UBIFS_KEY_H__
3939

40+
/**
41+
* key_mask_hash - mask a valid hash value.
42+
* @val: value to be masked
43+
*
44+
* We use hash values as offset in directories, so values %0 and %1 are
45+
* reserved for "." and "..". %2 is reserved for "end of readdir" marker. This
46+
* function makes sure the reserved values are not used.
47+
*/
48+
static inline uint32_t key_mask_hash(uint32_t hash)
49+
{
50+
hash &= UBIFS_S_KEY_HASH_MASK;
51+
if (unlikely(hash <= 2))
52+
hash += 3;
53+
return hash;
54+
}
55+
4056
/**
4157
* key_r5_hash - R5 hash function (borrowed from reiserfs).
4258
* @s: direntry name
@@ -54,16 +70,7 @@ static inline uint32_t key_r5_hash(const char *s, int len)
5470
str++;
5571
}
5672

57-
a &= UBIFS_S_KEY_HASH_MASK;
58-
59-
/*
60-
* We use hash values as offset in directories, so values %0 and %1 are
61-
* reserved for "." and "..". %2 is reserved for "end of readdir"
62-
* marker.
63-
*/
64-
if (unlikely(a >= 0 && a <= 2))
65-
a += 3;
66-
return a;
73+
return key_mask_hash(a);
6774
}
6875

6976
/**
@@ -77,10 +84,7 @@ static inline uint32_t key_test_hash(const char *str, int len)
7784

7885
len = min_t(uint32_t, len, 4);
7986
memcpy(&a, str, len);
80-
a &= UBIFS_S_KEY_HASH_MASK;
81-
if (unlikely(a >= 0 && a <= 2))
82-
a += 3;
83-
return a;
87+
return key_mask_hash(a);
8488
}
8589

8690
/**

0 commit comments

Comments
 (0)