1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 #ifndef HASH_H 3 #define HASH_H 4 5 static inline unsigned int hash_str(const char *s) 6 { 7 /* fnv32 hash */ 8 unsigned int hash = 2166136261U; 9 10 for (; *s; s++) 11 hash = (hash ^ *s) * 0x01000193; 12 return hash; 13 } 14 15 /* simplified version of functions from include/linux/hash.h */ 16 #define GOLDEN_RATIO_32 0x61C88647 17 18 static inline unsigned int hash_32(unsigned int val) 19 { 20 return 0x61C88647 * val; 21 } 22 23 static inline unsigned int hash_ptr(const void *ptr) 24 { 25 return hash_32((unsigned int)(unsigned long)ptr); 26 } 27 28 #endif /* HASH_H */ 29