From patchwork Fri Mar 8 20:39:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 10845415 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D2A1E17E9 for ; Fri, 8 Mar 2019 20:39:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4B8A2F66D for ; Fri, 8 Mar 2019 20:39:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4BCD2F6E8; Fri, 8 Mar 2019 20:39:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3842A2F66D for ; Fri, 8 Mar 2019 20:39:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726754AbfCHUj2 (ORCPT ); Fri, 8 Mar 2019 15:39:28 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:44756 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726536AbfCHUj2 (ORCPT ); Fri, 8 Mar 2019 15:39:28 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: ezequiel) with ESMTPSA id 5E6BC280736 From: Ezequiel Garcia To: lucas.demarchi@intel.com, linux-modules@vger.kernel.org Cc: Ezequiel Garcia 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> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: owner-linux-modules@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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[])