Skip to contentSkip to conversation

dm: change dm_get_target_type() to check for module load error

PATCH NAK Shuah Khan 2 participants 3 messages Oct 4, 2021 – Oct 6, 2021 Device mapper

lore
Share & tools
lore

Shuah Khan

author
#0 lore raw

PATCH 1/1 dm: change dm_get_target_type() to check for module load error

dm_get_target_type() doesn't check error return from request_module(). Change to check for error and return NULL instead of trying to get target type again which would fail.

---
 drivers/md/dm-target.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/md/dm-target.c +8 -3
index 64dd0b34fcf4..0789e9f91d3a 100644
@@ -41,17 +41,22 @@ static struct target_type *get_target_type(const char *name)
 	return tt;
 }
 
-static void load_module(const char *name)
+static int load_module(const char *name)
 {
-	request_module("dm-%s", name);
+	return request_module("dm-%s", name);
 }
 
 struct target_type *dm_get_target_type(const char *name)
 {
 	struct target_type *tt = get_target_type(name);
+	int ret;
 
 	if (!tt) {
-		load_module(name);
+		ret = load_module(name);
+		if (ret < 0) {
+			pr_err("Module %s load failed %d\n", name, ret);
+			return NULL;
+		}
 		tt = get_target_type(name);
 	}
 
Signature · 1 line
2.30.2
Nacked-by on v1 1/1 NAK
#1 lore raw
Quoted 42 lines · Shuah Khan

dm_get_target_type() doesn't check error return from request_module(). Change to check for error and return NULL instead of trying to get target type again which would fail.

---
 drivers/md/dm-target.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/md/dm-target.c +8 -3
index 64dd0b34fcf4..0789e9f91d3a 100644
@@ -41,17 +41,22 @@ static struct target_type *get_target_type(const char *name)
 	return tt;
 }
 
-static void load_module(const char *name)
+static int load_module(const char *name)
 {
-	request_module("dm-%s", name);
+	return request_module("dm-%s", name);
 }
 
 struct target_type *dm_get_target_type(const char *name)
 {
 	struct target_type *tt = get_target_type(name);
+	int ret;
 
 	if (!tt) {
-		load_module(name);
+		ret = load_module(name);
+		if (ret < 0) {
+			pr_err("Module %s load failed %d\n", name, ret);
+			return NULL;
+		}
 		tt = get_target_type(name);
 	}
 
Signature · 1 line
2.30.2

While I appreciate your intent, the reality is that multiple targets may be made available in a given module. And so loading one dm module may bring in access to N targets. There isn't a rigid 1:1 mapping of target modules to names. And there may not even be a loadable module that has the name dm-${name} -- but that doesn't mean the target_type won;t have been loaded into DM for it to access.

So all said, your patch is bogus and would break DM and user experience:

But thanks for raising your concern.

author
#2 lore raw
Quoted 42 lines · Mike Snitzer
Quoted 39 lines · Shuah Khan

dm_get_target_type() doesn't check error return from request_module(). Change to check for error and return NULL instead of trying to get target type again which would fail.

---
  drivers/md/dm-target.c | 11 ++++++++---
  1 file changed, 8 insertions(+), 3 deletions(-)
drivers/md/dm-target.c +8 -3
index 64dd0b34fcf4..0789e9f91d3a 100644
@@ -41,17 +41,22 @@ static struct target_type *get_target_type(const char *name)
  	return tt;
  }
 
-static void load_module(const char *name)
+static int load_module(const char *name)
  {
-	request_module("dm-%s", name);
+	return request_module("dm-%s", name);
  }
 
  struct target_type *dm_get_target_type(const char *name)
  {
  	struct target_type *tt = get_target_type(name);
+	int ret;
 
  	if (!tt) {
-		load_module(name);
+		ret = load_module(name);
+		if (ret < 0) {
+			pr_err("Module %s load failed %d\n", name, ret);
+			return NULL;
+		}
  		tt = get_target_type(name);
  	}
 
Quoted 11 lines
Quoted 3 lines
Signature · 1 line
2.30.2

While I appreciate your intent, the reality is that multiple targets may be made available in a given module. And so loading one dm module may bring in access to N targets. There isn't a rigid 1:1 mapping of target modules to names. And there may not even be a loadable module that has the name dm-${name} -- but that doesn't mean the target_type won;t have been loaded into DM for it to access.

Thanks for the explanation.

-- Shuah