diff mbox series

[4/8] arm64: stacktrace: add stackinfo_on_stack() helper

Message ID 20220801121209.2479449-5-mark.rutland@arm.com (mailing list archive)
State New, archived
Headers show
Series arm64: stacktrace: cleanups and improvements | expand

Commit Message

Mark Rutland Aug. 1, 2022, 12:12 p.m. UTC
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>
Cc: Fuad Tabba <tabba@google.com>
Cc: Kalesh Singh <kaleshsingh@google.com>
Cc: Madhavan T. Venkataraman <madvenka@linux.microsoft.com>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Mark Brown <broonie@kernel.org>
---
 arch/arm64/include/asm/stacktrace/common.h | 29 ++++++++++++++++------
 1 file changed, 21 insertions(+), 8 deletions(-)

Comments

Mark Brown Aug. 1, 2022, 3:56 p.m. UTC | #1
On Mon, Aug 01, 2022 at 01:12:05PM +0100, Mark Rutland wrote:
> 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.

Reviewed-by: Mark Brown <broonie@kernel.org>
Kalesh Singh Aug. 2, 2022, 5 a.m. UTC | #2
On Mon, Aug 1, 2022 at 5:12 AM Mark Rutland <mark.rutland@arm.com> wrote:
>
> 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>
> Cc: Fuad Tabba <tabba@google.com>
> Cc: Kalesh Singh <kaleshsingh@google.com>
> Cc: Madhavan T. Venkataraman <madvenka@linux.microsoft.com>
> Cc: Marc Zyngier <maz@kernel.org>
> Cc: Mark Brown <broonie@kernel.org>

Reviewed-by: Kalesh Singh <kaleshsingh@google.com>

> ---
>  arch/arm64/include/asm/stacktrace/common.h | 29 ++++++++++++++++------
>  1 file changed, 21 insertions(+), 8 deletions(-)
>
> diff --git a/arch/arm64/include/asm/stacktrace/common.h b/arch/arm64/include/asm/stacktrace/common.h
> index 676002d7d333c..9ed7feb493a36 100644
> --- a/arch/arm64/include/asm/stacktrace/common.h
> +++ b/arch/arm64/include/asm/stacktrace/common.h
> @@ -66,21 +66,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;
>  }
>
> --
> 2.30.2
>
diff mbox series

Patch

diff --git a/arch/arm64/include/asm/stacktrace/common.h b/arch/arm64/include/asm/stacktrace/common.h
index 676002d7d333c..9ed7feb493a36 100644
--- a/arch/arm64/include/asm/stacktrace/common.h
+++ b/arch/arm64/include/asm/stacktrace/common.h
@@ -66,21 +66,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;
 }