diff mbox series

tools: Print a message if refcnt attribute is missing

Message ID 20190308203907.17030-1-ezequiel@collabora.com (mailing list archive)
State New, archived
Headers show
Series tools: Print a message if refcnt attribute is missing | expand

Commit Message

Ezequiel Garcia March 8, 2019, 8:39 p.m. UTC
Currently, check_module_inuse returns a wrong user message
if the kernel is built without module unloading support.

Fix it by returning a more specific error, in case 'refcnt'
attribute is missing.
---
 tools/remove.c | 9 ++++++---
 tools/rmmod.c  | 9 ++++++---
 2 files changed, 12 insertions(+), 6 deletions(-)

Comments

Lucas De Marchi March 8, 2019, 9:09 p.m. UTC | #1
On Fri, Mar 08, 2019 at 05:39:07PM -0300, Ezequiel Garcia wrote:
>Currently, check_module_inuse returns a wrong user message
>if the kernel is built without module unloading support.
>
>Fix it by returning a more specific error, in case 'refcnt'
>attribute is missing.

Applied, thanks.

Lucas De Marchi

>---
> tools/remove.c | 9 ++++++---
> tools/rmmod.c  | 9 ++++++---
> 2 files changed, 12 insertions(+), 6 deletions(-)
>
>diff --git a/tools/remove.c b/tools/remove.c
>index 07e2cc0c83cd..387ef0ed17ce 100644
>--- a/tools/remove.c
>+++ b/tools/remove.c
>@@ -44,7 +44,7 @@ static void help(void)
>
> static int check_module_inuse(struct kmod_module *mod) {
> 	struct kmod_list *holders;
>-	int state;
>+	int state, ret;
>
> 	state = kmod_module_get_initstate(mod);
>
>@@ -74,12 +74,15 @@ static int check_module_inuse(struct kmod_module *mod) {
> 		return -EBUSY;
> 	}
>
>-	if (kmod_module_get_refcnt(mod) != 0) {
>+	ret = kmod_module_get_refcnt(mod);
>+	if (ret > 0) {
> 		ERR("Module %s is in use\n", kmod_module_get_name(mod));
> 		return -EBUSY;
>+	} else if (ret == -ENOENT) {
>+		ERR("Module unloading is not supported\n");
> 	}
>
>-	return 0;
>+	return ret;
> }
>
> static int do_remove(int argc, char *argv[])
>diff --git a/tools/rmmod.c b/tools/rmmod.c
>index bcdea4c57262..3942e7b439bd 100644
>--- a/tools/rmmod.c
>+++ b/tools/rmmod.c
>@@ -63,7 +63,7 @@ static void help(void)
>
> static int check_module_inuse(struct kmod_module *mod) {
> 	struct kmod_list *holders;
>-	int state;
>+	int state, ret;
>
> 	state = kmod_module_get_initstate(mod);
>
>@@ -93,12 +93,15 @@ static int check_module_inuse(struct kmod_module *mod) {
> 		return -EBUSY;
> 	}
>
>-	if (kmod_module_get_refcnt(mod) != 0) {
>+	ret = kmod_module_get_refcnt(mod);
>+	if (ret > 0) {
> 		ERR("Module %s is in use\n", kmod_module_get_name(mod));
> 		return -EBUSY;
>+	} else if (ret == -ENOENT) {
>+		ERR("Module unloading is not supported\n");
> 	}
>
>-	return 0;
>+	return ret;
> }
>
> static int do_rmmod(int argc, char *argv[])
>-- 
>2.20.1
>
diff mbox series

Patch

diff --git a/tools/remove.c b/tools/remove.c
index 07e2cc0c83cd..387ef0ed17ce 100644
--- a/tools/remove.c
+++ b/tools/remove.c
@@ -44,7 +44,7 @@  static void help(void)
 
 static int check_module_inuse(struct kmod_module *mod) {
 	struct kmod_list *holders;
-	int state;
+	int state, ret;
 
 	state = kmod_module_get_initstate(mod);
 
@@ -74,12 +74,15 @@  static int check_module_inuse(struct kmod_module *mod) {
 		return -EBUSY;
 	}
 
-	if (kmod_module_get_refcnt(mod) != 0) {
+	ret = kmod_module_get_refcnt(mod);
+	if (ret > 0) {
 		ERR("Module %s is in use\n", kmod_module_get_name(mod));
 		return -EBUSY;
+	} else if (ret == -ENOENT) {
+		ERR("Module unloading is not supported\n");
 	}
 
-	return 0;
+	return ret;
 }
 
 static int do_remove(int argc, char *argv[])
diff --git a/tools/rmmod.c b/tools/rmmod.c
index bcdea4c57262..3942e7b439bd 100644
--- a/tools/rmmod.c
+++ b/tools/rmmod.c
@@ -63,7 +63,7 @@  static void help(void)
 
 static int check_module_inuse(struct kmod_module *mod) {
 	struct kmod_list *holders;
-	int state;
+	int state, ret;
 
 	state = kmod_module_get_initstate(mod);
 
@@ -93,12 +93,15 @@  static int check_module_inuse(struct kmod_module *mod) {
 		return -EBUSY;
 	}
 
-	if (kmod_module_get_refcnt(mod) != 0) {
+	ret = kmod_module_get_refcnt(mod);
+	if (ret > 0) {
 		ERR("Module %s is in use\n", kmod_module_get_name(mod));
 		return -EBUSY;
+	} else if (ret == -ENOENT) {
+		ERR("Module unloading is not supported\n");
 	}
 
-	return 0;
+	return ret;
 }
 
 static int do_rmmod(int argc, char *argv[])