dm persistent data: fix invalid calls to vt->inc and vt->dec
Mikulas Patocka
maintainerPATCH 1/1 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.
--- drivers/md/persistent-data/dm-array.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/md/persistent-data/dm-array.c +6 -6
@@ -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); }
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] dm persistent data: missing Fixes trailer for commit be500ed721a6 --
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 <[email protected]>
Quoted 8 lines
dm persistent data: fix invalid calls to
vt->incandvt->decThe dm-array library called
vt->incandvt->decwith invalid arguments. None of the users of the library actually use the callbacks, so the bug was latent.Signed-off-by Mikulas Patocka <[email protected]>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:
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 30 lines · Mikulas Patocka
The dm-array library called
vt->incandvt->decwith invalid arguments. None of the users of the library actually use the callbacks, so the bug was latent.Signed-off-by Mikulas Patocka <[email protected]>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
===================================================================drivers/md/persistent-data/dm-array.c +1
-3@@ -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)
drivers/md/persistent-data/dm-array.c static int alloc_ablock(struct dm_array_ · line 213
Quoted 10 lines
drivers/md/persistent-data/dm-array.c +4
-2- 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:
(quoted diff) +0 -0
b/drivers/md/persistent-data/dm-array.c
index 961fa3c1439a..f1afbb89bce6 100644
drivers/md/persistent-data/dm-array.c +0 -0
@@ -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);}
drivers/md/persistent-data/dm-array.c static void trim_ablock(struct dm_array_ · line 233
Quoted 8 lines
drivers/md/persistent-data/dm-array.c +1
-1@@ -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.