[bug report] maple_tree: add MAS_UNDERFLOW and MAS_OVERFLOW states
Dan Carpenter
dan.carpenter at linaro.org
Wed Sep 27 05:42:29 PDT 2023
Hello Liam R. Howlett,
The patch 234d37113ef0: "maple_tree: add MAS_UNDERFLOW and
MAS_OVERFLOW states" from Sep 21, 2023 (linux-next), leads to the
following Smatch static checker warning:
lib/maple_tree.c:4653 mas_next_slot()
warn: ignoring unreachable code.
lib/maple_tree.c
4603 static void *mas_next_slot(struct ma_state *mas, unsigned long max, bool empty,
4604 bool set_overflow)
4605 {
4606 void __rcu **slots;
4607 unsigned long *pivots;
4608 unsigned long pivot;
4609 enum maple_type type;
4610 struct maple_node *node;
4611 unsigned char data_end;
4612 unsigned long save_point = mas->last;
4613 void *entry;
4614
4615 retry:
4616 node = mas_mn(mas);
4617 type = mte_node_type(mas->node);
4618 pivots = ma_pivots(node, type);
4619 data_end = ma_data_end(node, type, pivots, mas->max);
4620 if (unlikely(mas_rewalk_if_dead(mas, node, save_point)))
4621 goto retry;
4622
4623 if (mas->max >= max) {
4624 if (likely(mas->offset < data_end))
4625 pivot = pivots[mas->offset];
4626 else
4627 goto overflow;
4628
4629 if (unlikely(mas_rewalk_if_dead(mas, node, save_point)))
4630 goto retry;
4631
4632 if (pivot >= max)
4633 goto overflow;
4634 }
4635
4636 if (likely(mas->offset < data_end)) {
4637 mas->index = pivots[mas->offset] + 1;
4638 again:
4639 mas->offset++;
4640 if (likely(mas->offset < data_end))
4641 mas->last = pivots[mas->offset];
4642 else
4643 mas->last = mas->max;
4644 } else {
4645 if (mas_next_node(mas, node, max)) {
4646 mas_rewalk(mas, save_point);
4647 goto retry;
4648 }
4649
4650 if (WARN_ON_ONCE(mas_is_none(mas))) {
4651 mas->node = MAS_OVERFLOW;
Should this set ->node even if set_overflow is false?
4652 return NULL;
--> 4653 goto overflow;
Unreachable
4654 }
4655
4656 mas->offset = 0;
4657 mas->index = mas->min;
4658 node = mas_mn(mas);
4659 type = mte_node_type(mas->node);
4660 pivots = ma_pivots(node, type);
4661 mas->last = pivots[0];
4662 }
4663
4664 slots = ma_slots(node, type);
4665 entry = mt_slot(mas->tree, slots, mas->offset);
4666 if (unlikely(mas_rewalk_if_dead(mas, node, save_point)))
4667 goto retry;
4668
4669 if (entry)
4670 return entry;
4671
4672 if (!empty) {
4673 if (mas->last >= max)
4674 goto overflow;
4675
4676 mas->index = mas->last + 1;
4677 /* Node cannot end on NULL, so it's safe to short-cut here */
4678 goto again;
4679 }
4680
4681 return entry;
4682
4683 overflow:
4684 if (set_overflow)
4685 mas->node = MAS_OVERFLOW;
4686 return NULL;
4687 }
regards,
dan carpenter
More information about the maple-tree
mailing list