arm64: stacktrace: add stackinfo_on_stack() helper
authorMark Rutland <mark.rutland@arm.com>
Thu, 1 Sep 2022 13:06:42 +0000 (14:06 +0100)
committerCatalin Marinas <catalin.marinas@arm.com>
Fri, 9 Sep 2022 11:30:07 +0000 (12:30 +0100)
Factor the core predicate out of on_stack() into a helper which can be
used on a pre-populated stack_info.

There should be no functional change as a result of this patch.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Kalesh Singh <kaleshsingh@google.com>
Reviewed-by: Madhavan T. Venkataraman <madvenka@linux.microsoft.com>
Reviewed-by: Mark Brown <broonie@kernel.org>
Cc: Fuad Tabba <tabba@google.com>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20220901130646.1316937-6-mark.rutland@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
arch/arm64/include/asm/stacktrace/common.h

index a74fa301fe953ad694b3c64da7efa45cc3b4cee8..81c21378b1ac9e2f1b6b398a70b813ab7696e75f 100644 (file)
@@ -65,21 +65,34 @@ struct unwind_state {
        struct task_struct *task;
 };
 
+static inline bool stackinfo_on_stack(const struct stack_info *info,
+                                     unsigned long sp, unsigned long size)
+{
+       if (!info->low)
+               return false;
+
+       if (sp < info->low || sp + size < sp || sp + size > info->high)
+               return false;
+
+       return true;
+}
+
 static inline bool on_stack(unsigned long sp, unsigned long size,
                            unsigned long low, unsigned long high,
                            enum stack_type type, struct stack_info *info)
 {
-       if (!low)
-               return false;
+       struct stack_info tmp = {
+               .low = low,
+               .high = high,
+               .type = type,
+       };
 
-       if (sp < low || sp + size < sp || sp + size > high)
+       if (!stackinfo_on_stack(&tmp, sp, size))
                return false;
 
-       if (info) {
-               info->low = low;
-               info->high = high;
-               info->type = type;
-       }
+       if (info)
+               *info = tmp;
+
        return true;
 }