Re: [PATCH] dm btree: Remove redundant index condition

From: Mikulas Patocka

Date: Mon Nov 16 2026 - 15:00:47 EST




On Fri, 6 Nov 2026, Donut Oreo Computer I wrote:

> The index is unsigned, so checking whether i is non-negative is
> unnecessary.

Really?

In the caller, there is

"unsigned int level, index = -1, last_level = info->levels - 1;"

In btree_insert_raw, there is "int r, i = *index, top = 1;"

If you cast -1 to unsigned int and then cast it back to int, you get -1.

So, it doesn't seem like an obvious dead code to me.

Mikulas

> Signed-off-by: Donut Oreo Computer <donut.oreo.computer@xxxxxxxxx>
> ---
> drivers/md/persistent-data/dm-btree.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/md/persistent-data/dm-btree.c
> b/drivers/md/persistent-data/dm-btree.c
> index dd02eee4a23c..b7ac2f6d1d71 100644
> --- a/drivers/md/persistent-data/dm-btree.c
> +++ b/drivers/md/persistent-data/dm-btree.c
> @@ -1108,7 +1108,7 @@ static int btree_insert_raw(struct shadow_spine
> *s, dm_block_t root,
> * see a way to do this automatically as part of the spine
> * op.
> */
> - if (shadow_has_parent(s) && i >= 0) { /* FIXME: second
> clause unness. */
> + if (shadow_has_parent(s)) {
> __le64 location =
> cpu_to_le64(dm_block_location(shadow_current(s)));
>
> __dm_bless_for_disk(&location);
> --
> 2.56.0
>