* [PATCH] dm persistent data: fix invalid calls to vt->inc and vt->dec
@ 2026-11-23 20:54 Mikulas Patocka
2026-11-23 21:00 ` sashiko-bot
2026-11-27 9:22 ` Ming Hung Tsai
0 siblings, 2 replies; 3+ messages in thread
From: Mikulas Patocka @ 2026-11-23 20:54 UTC (permalink / raw)
To: Alasdair Kergon, Mike Snitzer, Benjamin Marzinski, Ming-Hung Tsai,
dm-devel
The dm-array library called vt->inc and vt->dec with invalid arguments.
None of the users of the library actually use the callbacks, so the bug
was latent.
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Assisted-by: Claude:claude-opus-5
---
drivers/md/persistent-data/dm-array.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
Index: linux-2.6/drivers/md/persistent-data/dm-array.c
===================================================================
--- linux-2.6.orig/drivers/md/persistent-data/dm-array.c
+++ linux-2.6/drivers/md/persistent-data/dm-array.c
@@ -196,18 +196,18 @@ static int alloc_ablock(struct dm_array_
static void fill_ablock(struct dm_array_info *info, struct array_block *ab,
const void *value, unsigned int new_nr)
{
- uint32_t nr_entries, delta, i;
+ uint32_t nr_entries, i;
struct dm_btree_value_type *vt = &info->value_type;
BUG_ON(new_nr > le32_to_cpu(ab->max_entries));
BUG_ON(new_nr < le32_to_cpu(ab->nr_entries));
nr_entries = le32_to_cpu(ab->nr_entries);
- delta = new_nr - nr_entries;
- if (vt->inc)
- vt->inc(vt->context, value, delta);
- for (i = nr_entries; i < new_nr; i++)
+ for (i = nr_entries; i < new_nr; i++) {
+ if (vt->inc)
+ vt->inc(vt->context, value, 1);
memcpy(element_at(info, ab, i), value, vt->size);
+ }
ab->nr_entries = cpu_to_le32(new_nr);
}
@@ -228,7 +228,7 @@ static void trim_ablock(struct dm_array_
nr_entries = le32_to_cpu(ab->nr_entries);
delta = nr_entries - new_nr;
if (vt->dec)
- vt->dec(vt->context, element_at(info, ab, new_nr - 1), delta);
+ vt->dec(vt->context, element_at(info, ab, new_nr), delta);
ab->nr_entries = cpu_to_le32(new_nr);
}
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] dm persistent data: fix invalid calls to vt->inc and vt->dec 2026-11-23 20:54 [PATCH] dm persistent data: fix invalid calls to vt->inc and vt->dec Mikulas Patocka @ 2026-11-23 21:00 ` sashiko-bot 2026-11-27 9:22 ` Ming Hung Tsai 1 sibling, 0 replies; 3+ messages in thread From: sashiko-bot @ 2026-11-23 21:00 UTC (permalink / raw) To: Mikulas Patocka, Alasdair Kergon, Mike Snitzer, Benjamin Marzinski, Ming-Hung Tsai, dm-devel Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] dm persistent data: missing Fixes trailer for commit be500ed721a6 -- commit 98fa2d52c80bc26e5eb99bb6a56f6fe2672f889c Author: Mikulas Patocka <mpatocka@redhat.com> > dm persistent data: fix invalid calls to vt->inc and vt->dec > > The dm-array library called vt->inc and vt->dec with invalid arguments. > None of the users of the library actually use the callbacks, so the bug > was latent. > > Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> > Assisted-by: Claude:claude-opus-5 [Severity: Low] This fixes the vt->inc() and vt->dec() calls updated in fill_ablock() and trim_ablock(). Should this include: Fixes: be500ed721a6 ("dm space maps: improve performance with inc/dec on ranges of blocks") -- Sashiko AI review · https://sashiko.dev/#/patchset/9f8ed9a9-fb35-7a4d-4877-430268010b43@redhat.com?part=1 ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] dm persistent data: fix invalid calls to vt->inc and vt->dec 2026-11-23 20:54 [PATCH] dm persistent data: fix invalid calls to vt->inc and vt->dec Mikulas Patocka 2026-11-23 21:00 ` sashiko-bot @ 2026-11-27 9:22 ` Ming Hung Tsai 1 sibling, 0 replies; 3+ messages in thread From: Ming Hung Tsai @ 2026-11-27 9:22 UTC (permalink / raw) To: Mikulas Patocka Cc: Alasdair Kergon, Mike Snitzer, Benjamin Marzinski, dm-devel On Tue, Nov 24, 2026 at 4:54 AM Mikulas Patocka <mpatocka@redhat.com> wrote: > > The dm-array library called vt->inc and vt->dec with invalid arguments. > None of the users of the library actually use the callbacks, so the bug > was latent. > > Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> > Assisted-by: Claude:claude-opus-5 > > --- > drivers/md/persistent-data/dm-array.c | 12 ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) > > Index: linux-2.6/drivers/md/persistent-data/dm-array.c > =================================================================== > --- linux-2.6.orig/drivers/md/persistent-data/dm-array.c > +++ linux-2.6/drivers/md/persistent-data/dm-array.c > @@ -196,18 +196,18 @@ static int alloc_ablock(struct dm_array_ > static void fill_ablock(struct dm_array_info *info, struct array_block *ab, > const void *value, unsigned int new_nr) > { > - uint32_t nr_entries, delta, i; > + uint32_t nr_entries, i; > struct dm_btree_value_type *vt = &info->value_type; > > BUG_ON(new_nr > le32_to_cpu(ab->max_entries)); > BUG_ON(new_nr < le32_to_cpu(ab->nr_entries)); > > nr_entries = le32_to_cpu(ab->nr_entries); > - delta = new_nr - nr_entries; > - if (vt->inc) > - vt->inc(vt->context, value, delta); > - for (i = nr_entries; i < new_nr; i++) > + for (i = nr_entries; i < new_nr; i++) { > + if (vt->inc) > + vt->inc(vt->context, value, 1); > memcpy(element_at(info, ab, i), value, vt->size); > + } > ab->nr_entries = cpu_to_le32(new_nr); > } > I think we can keep the range call from be500ed721a6 instead. Copy the values first, then call inc() once on the new entries: diff --git a/drivers/md/persistent-data/dm-array.c b/drivers/md/persistent-data/dm-array.c index 961fa3c1439a..f1afbb89bce6 100644 --- a/drivers/md/persistent-data/dm-array.c +++ b/drivers/md/persistent-data/dm-array.c @@ -204,10 +204,10 @@ static void fill_ablock(struct dm_array_info *info, struct array_block *ab, nr_entries = le32_to_cpu(ab->nr_entries); delta = new_nr - nr_entries; - if (vt->inc) - vt->inc(vt->context, value, delta); for (i = nr_entries; i < new_nr; i++) memcpy(element_at(info, ab, i), value, vt->size); + if (vt->inc) + vt->inc(vt->context, element_at(info, ab, nr_entries), delta); ab->nr_entries = cpu_to_le32(new_nr); } > @@ -228,7 +228,7 @@ static void trim_ablock(struct dm_array_ > nr_entries = le32_to_cpu(ab->nr_entries); > delta = nr_entries - new_nr; > if (vt->dec) > - vt->dec(vt->context, element_at(info, ab, new_nr - 1), delta); > + vt->dec(vt->context, element_at(info, ab, new_nr), delta); > ab->nr_entries = cpu_to_le32(new_nr); > } The second half looks correct to me. The range to dec starts at new_ne, not new_nr - 1. ^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-27 9:22 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-23 20:54 [PATCH] dm persistent data: fix invalid calls to vt->inc and vt->dec Mikulas Patocka 2026-11-23 21:00 ` sashiko-bot 2026-11-27 9:22 ` Ming Hung Tsai
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.