Merge tag 'close-range-openat2-v5.11' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-microblaze.git] / lib / stackdepot.c
index 81c69c0..2caffc6 100644 (file)
@@ -20,6 +20,7 @@
  */
 
 #include <linux/gfp.h>
+#include <linux/interrupt.h>
 #include <linux/jhash.h>
 #include <linux/kernel.h>
 #include <linux/mm.h>
@@ -202,9 +203,20 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle,
                               unsigned long **entries)
 {
        union handle_parts parts = { .handle = handle };
-       void *slab = stack_slabs[parts.slabindex];
+       void *slab;
        size_t offset = parts.offset << STACK_ALLOC_ALIGN;
-       struct stack_record *stack = slab + offset;
+       struct stack_record *stack;
+
+       *entries = NULL;
+       if (parts.slabindex > depot_index) {
+               WARN(1, "slab index %d out of bounds (%d) for stack id %08x\n",
+                       parts.slabindex, depot_index, handle);
+               return 0;
+       }
+       slab = stack_slabs[parts.slabindex];
+       if (!slab)
+               return 0;
+       stack = slab + offset;
 
        *entries = stack->entries;
        return stack->size;
@@ -305,3 +317,26 @@ fast_exit:
        return retval;
 }
 EXPORT_SYMBOL_GPL(stack_depot_save);
+
+static inline int 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);
+}
+
+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);