Skip to contentSkip to conversation

Minor DM fixes

PATCH New Benjamin Marzinski 1 participant 3 messages Apr 15, 2025 Device mapper

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

cover Minor DM fixes

The first patch is a repost of a patch I posted almost a year ago. I think it must have fallen through the cracks somehow.

https://lore.kernel.org/all/[email protected]/

The second in an unrelated fix for realloc_argv()

Benjamin Marzinski (2):
dm: remove unneeded kvfree from alloc_targets
dm: always update the array size in realloc_argv on success

 drivers/md/dm-table.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
2.48.1
author maintainer
#1 lore raw

PATCH 1/2 dm: remove unneeded kvfree from alloc_targets

alloc_targets() is always called with a newly initialized table where t->highs == NULL.

---
 drivers/md/dm-table.c | 1 -
 1 file changed, 1 deletion(-)
drivers/md/dm-table.c +0 -1
index 69d4a0e0e613..31e2f9071ca8 100644
@@ -117,7 +117,6 @@ static int alloc_targets(struct dm_table *t, unsigned int num)
 	n_targets = (struct dm_target *) (n_highs + num);
 
 	memset(n_highs, -1, sizeof(*n_highs) * num);
-	kvfree(t->highs);
 
 	t->num_allocated = num;
 	t->highs = n_highs;
Signature · 1 line
2.48.1
author maintainer
#2 lore raw

PATCH 2/2 dm: always update the array size in realloc_argv on success

In reply to Benjamin Marzinski

realloc_argv() was only updating the array size if it was called with old_argv already allocated. The first time it was called to create an argv array, it would allocate the array but return the array size as zero. dm_split_args() would think that it couldn't store any arguments in the array and would call realloc_argv() again, causing it to reallocate the initial slots (this time using GPF_KERNEL) and finally return a size. Aside from being wasteful, this could cause deadlocks on targets that need to process messages without starting new IO. Instead, realloc_argv should always update the allocated array size on success.

Fixes a0651926553c ("dm table: don't copy from a NULL pointer in realloc_argv()")
---
 drivers/md/dm-table.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/md/dm-table.c +3 -2
index 31e2f9071ca8..46b0e4813a73 100644
@@ -522,9 +522,10 @@ static char **realloc_argv(unsigned int *size, char **old_argv)
 		gfp = GFP_NOIO;
 	}
 	argv = kmalloc_array(new_size, sizeof(*argv), gfp);
-	if (argv && old_argv) {
-		memcpy(argv, old_argv, *size * sizeof(*argv));
+	if (argv) {
 		*size = new_size;
+		if (old_argv)
+			memcpy(argv, old_argv, *size * sizeof(*argv));
 	}
 
 	kfree(old_argv);
Signature · 1 line
2.48.1