Linux-Modules Archive on lore.kernel.org
 help / color / Atom feed
From: Ezequiel Garcia <ezequiel@collabora.com>
To: lucas.demarchi@intel.com, linux-modules@vger.kernel.org
Cc: Ezequiel Garcia <ezequiel@collabora.com>
Subject: [PATCH] tools: Print a message if refcnt attribute is missing
Date: Fri,  8 Mar 2019 17:39:07 -0300
Message-ID: <20190308203907.17030-1-ezequiel@collabora.com> (raw)

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(-)

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


             reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-08 20:39 Ezequiel Garcia [this message]
2019-03-08 21:09 ` Lucas De Marchi

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190308203907.17030-1-ezequiel@collabora.com \
    --to=ezequiel@collabora.com \
    --cc=linux-modules@vger.kernel.org \
    --cc=lucas.demarchi@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-Modules Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-modules/0 linux-modules/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-modules linux-modules/ https://lore.kernel.org/linux-modules \
		linux-modules@vger.kernel.org linux-modules@archiver.kernel.org
	public-inbox-index linux-modules


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-modules


AGPL code for this site: git clone https://public-inbox.org/ public-inbox