maple_tree: reduce user error potential
[platform/kernel/linux-starfive.git] / lib / maple_tree.c
index f8e1e85..360b4bb 100644 (file)
@@ -4731,6 +4731,11 @@ static inline void *mas_next_entry(struct ma_state *mas, unsigned long limit)
        unsigned long last;
        enum maple_type mt;
 
+       if (mas->index > limit) {
+               mas->index = mas->last = limit;
+               mas_pause(mas);
+               return NULL;
+       }
        last = mas->last;
 retry:
        offset = mas->offset;
@@ -4837,6 +4842,11 @@ static inline void *mas_prev_entry(struct ma_state *mas, unsigned long min)
 {
        void *entry;
 
+       if (mas->index < min) {
+               mas->index = mas->last = min;
+               mas_pause(mas);
+               return NULL;
+       }
 retry:
        while (likely(!mas_is_none(mas))) {
                entry = mas_prev_nentry(mas, min, mas->index);