Merge tag 'xfs-5.5-merge-17' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
[linux-2.6-microblaze.git] / lib / vsprintf.c
index dee8fc4..7c488a1 100644 (file)
@@ -761,11 +761,38 @@ static int __init initialize_ptr_random(void)
 early_initcall(initialize_ptr_random);
 
 /* Maps a pointer to a 32 bit unique identifier. */
+static inline int __ptr_to_hashval(const void *ptr, unsigned long *hashval_out)
+{
+       unsigned long hashval;
+
+       if (static_branch_unlikely(&not_filled_random_ptr_key))
+               return -EAGAIN;
+
+#ifdef CONFIG_64BIT
+       hashval = (unsigned long)siphash_1u64((u64)ptr, &ptr_key);
+       /*
+        * Mask off the first 32 bits, this makes explicit that we have
+        * modified the address (and 32 bits is plenty for a unique ID).
+        */
+       hashval = hashval & 0xffffffff;
+#else
+       hashval = (unsigned long)siphash_1u32((u32)ptr, &ptr_key);
+#endif
+       *hashval_out = hashval;
+       return 0;
+}
+
+int ptr_to_hashval(const void *ptr, unsigned long *hashval_out)
+{
+       return __ptr_to_hashval(ptr, hashval_out);
+}
+
 static char *ptr_to_id(char *buf, char *end, const void *ptr,
                       struct printf_spec spec)
 {
        const char *str = sizeof(ptr) == 8 ? "(____ptrval____)" : "(ptrval)";
        unsigned long hashval;
+       int ret;
 
        /* When debugging early boot use non-cryptographically secure hash. */
        if (unlikely(debug_boot_weak_hash)) {
@@ -773,22 +800,13 @@ static char *ptr_to_id(char *buf, char *end, const void *ptr,
                return pointer_string(buf, end, (const void *)hashval, spec);
        }
 
-       if (static_branch_unlikely(&not_filled_random_ptr_key)) {
+       ret = __ptr_to_hashval(ptr, &hashval);
+       if (ret) {
                spec.field_width = 2 * sizeof(ptr);
                /* string length must be less than default_width */
                return error_string(buf, end, str, spec);
        }
 
-#ifdef CONFIG_64BIT
-       hashval = (unsigned long)siphash_1u64((u64)ptr, &ptr_key);
-       /*
-        * Mask off the first 32 bits, this makes explicit that we have
-        * modified the address (and 32 bits is plenty for a unique ID).
-        */
-       hashval = hashval & 0xffffffff;
-#else
-       hashval = (unsigned long)siphash_1u32((u32)ptr, &ptr_key);
-#endif
        return pointer_string(buf, end, (const void *)hashval, spec);
 }