[bug report] maple_tree: add MAS_UNDERFLOW and MAS_OVERFLOW states
Liam R. Howlett
Liam.Howlett at Oracle.com
Wed Sep 27 10:45:29 PDT 2023
* Dan Carpenter <dan.carpenter at linaro.org> [230927 08:42]:
> 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 {
...
> 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?
Yes. Perhaps a comment should be added to clarify.
The overflow condition is the only reason mas_next_node() will return
MAS_NONE. The only reason to keep the mas->node active is to avoid
re-walking the tree, but in this case mas->node == MAS_NONE, so the
re-walk will occur. Setting this to MAS_OVERFLOW will fix the
inconsistency in what the user expects to happen with the maple state in
later calls, so it is the correct thing to do here.
>
> 4652 return NULL;
> --> 4653 goto overflow;
>
> Unreachable
>
> 4654 }
...
Thanks for the bug report. That goto should be removed.
Regards,
Liam
More information about the maple-tree
mailing list