mediatek: mt76-6e-usb: Copied entire code from v5.18.y
[platform/kernel/linux-rpi.git] / kernel / stacktrace.c
index 9f8117c..9c62525 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/export.h>
 #include <linux/kallsyms.h>
 #include <linux/stacktrace.h>
+#include <linux/interrupt.h>
 
 /**
  * stack_trace_print - Print the entries in the stack trace
@@ -373,3 +374,32 @@ unsigned int stack_trace_save_user(unsigned long *store, unsigned int size)
 #endif /* CONFIG_USER_STACKTRACE_SUPPORT */
 
 #endif /* !CONFIG_ARCH_STACKWALK */
+
+static inline bool in_irqentry_text(unsigned long ptr)
+{
+       return (ptr >= (unsigned long)&__irqentry_text_start &&
+               ptr < (unsigned long)&__irqentry_text_end) ||
+               (ptr >= (unsigned long)&__softirqentry_text_start &&
+                ptr < (unsigned long)&__softirqentry_text_end);
+}
+
+/**
+ * filter_irq_stacks - Find first IRQ stack entry in trace
+ * @entries:   Pointer to stack trace array
+ * @nr_entries:        Number of entries in the storage array
+ *
+ * Return: Number of trace entries until IRQ stack starts.
+ */
+unsigned int filter_irq_stacks(unsigned long *entries, unsigned int nr_entries)
+{
+       unsigned int i;
+
+       for (i = 0; i < nr_entries; i++) {
+               if (in_irqentry_text(entries[i])) {
+                       /* Include the irqentry function into the stack. */
+                       return i + 1;
+               }
+       }
+       return nr_entries;
+}
+EXPORT_SYMBOL_GPL(filter_irq_stacks);