Looking at the code you posted, the only possible source for the General Protection Fault I can see is this line:
ret = table[hash_index].next;
You're not checking the size of table
, so perhaps you're accessing out-of-bounds memory? No way to be sure, without knowing how, where and what table
is declared as, and how you initialize it.
After looking at your comment, saying hash_index
, an unsigned int
, is the result of a modulus of the HASH_PRIME
macro, it could be that at some point, you're encountering possible signed-unsigned arithmetic issues, so that, despite the modulus on HASH_PRIME
, you are in fact going out of bounds. Perhaps add:
if (hash_index >= HASH_PRIME) hash_index = HASH_PRIME-1;//or error
Just for completeness' sake: as I pointed out in the comments, the functions you're using all use the kernel's u32
type. As it turns out, that was the reason for your code still accessing wrong memory. (Typed this update on phone... Hate it)