Skip to contentSkip to conversation

dm: init: fix max devices/targets checks

PATCH New Helen Koike 1 participant 1 message Apr 26, 2019 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm: init: fix max devices/targets checks

dm-init should allow up to DM_MAX_{DEVICES,TARGETS} for devices/targets, and not DM_MAX_{DEVICES,TARGETS} - 1.

Fix the checks and also fix the error message when the number of devices is surpassed.

---
Hi,

This patch was tested by manipulating DM_MAX_TARGETS and DM_MAX_DEVICES macros and making sure the test cases in the following test script[1] was passing or failing when they should.

[1] https://gitlab.collabora.com/koike/dm-cmdline-test

Thanks
Helen

 drivers/md/dm-init.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/md/dm-init.c +4 -4
index 4b76f84424c3..352e803f566e 100644
@@ -160,7 +160,7 @@ static int __init dm_parse_table(struct dm_device *dev, char *str)
 
 	while (table_entry) {
 		DMDEBUG("parsing table \"%s\"", str);
-		if (++dev->dmi.target_count >= DM_MAX_TARGETS) {
+		if (++dev->dmi.target_count > DM_MAX_TARGETS) {
 			DMERR("too many targets %u > %d",
 			      dev->dmi.target_count, DM_MAX_TARGETS);
 			return -EINVAL;
@@ -242,9 +242,9 @@ static int __init dm_parse_devices(struct list_head *devices, char *str)
 			return -ENOMEM;
 		list_add_tail(&dev->list, devices);
 
-		if (++ndev >= DM_MAX_DEVICES) {
-			DMERR("too many targets %u > %d",
-			      dev->dmi.target_count, DM_MAX_TARGETS);
+		if (++ndev > DM_MAX_DEVICES) {
+			DMERR("too many devices %lu > %d",
+			      ndev, DM_MAX_DEVICES);
 			return -EINVAL;
 		}
 
Signature · 1 line
2.20.1