diff --git a/lib/stackdepot.c b/lib/stackdepot.c
index 683b6a8ddade15b9f788bf86ed92a9ed71d3703f..890dcc2e984e363268939d2b678a3d5f117b7e56 100644
--- a/lib/stackdepot.c
+++ b/lib/stackdepot.c
@@ -154,8 +154,8 @@ static struct stack_record *stack_table[STACK_HASH_SIZE] = {
 static inline u32 hash_stack(unsigned long *entries, unsigned int size)
 {
 	return jhash2((u32 *)entries,
-			       size * sizeof(unsigned long) / sizeof(u32),
-			       STACK_HASH_SEED);
+		      array_size(size,  sizeof(*entries)) / sizeof(u32),
+		      STACK_HASH_SEED);
 }
 
 /* Use our own, non-instrumented version of memcmp().