From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail1.windriver.com (mail1.windriver.com [147.11.146.13]) by dpdk.org (Postfix) with ESMTP id 717565A3E for ; Mon, 1 May 2017 21:09:19 +0200 (CEST) Received: from ALA-HCA.corp.ad.wrs.com (ala-hca.corp.ad.wrs.com [147.11.189.40]) by mail1.windriver.com (8.15.2/8.15.1) with ESMTPS id v41J9Hu3029359 (version=TLSv1 cipher=AES128-SHA bits=128 verify=FAIL); Mon, 1 May 2017 12:09:17 -0700 (PDT) Received: from yow-dellw-ma.wrs.com (128.224.56.18) by ALA-HCA.corp.ad.wrs.com (147.11.189.50) with Microsoft SMTP Server id 14.3.294.0; Mon, 1 May 2017 12:09:17 -0700 From: Mark Asselstine To: CC: Date: Mon, 1 May 2017 15:09:09 -0400 Message-ID: <1493665749-10733-1-git-send-email-mark.asselstine@windriver.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain Subject: [dpdk-dev] [PATCH] dpdk-devbind.py: remove module search corner cases X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 May 2017 19:09:20 -0000 The existing code used to search for module files via modinfo has several corner cases which can result in it failing where it should be successful. The call to lower() would cause results returned by 'modinfo' to be forced to lowercase, results which were subsequently passed to exists() which is case sensitive. This was most likely done to capture all variants of failure strings modinfo might return (ie. ERROR/Error/error/...) without thought negative effect to the later call to exists(). For many this is a nonissue but if the module path included non-lowercase alpha characters, something which is easily possible with a non-lowercase kernel-extraversion string, this would cause an issue. We could move the call to lower() to the check for "error" but this still leaves possible corner cases, for modules or module paths with 'error' in them. Instead we will prevent modinfo's stderr from being used as a "good value" for path, meaning we either get a valid path from modinfo, or nothing at all. This removes all corner cases. Ultimately these preliminary checks are unnecessary as exists() will only return True if it is passed a valid path, passing it modinfo's stderr would fail. In keeping with the original code, however, we do some preliminary checks, but we are now free of corner cases. Signed-off-by: Mark Asselstine --- usertools/dpdk-devbind.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py index 7dc8e48..2d99e9d 100755 --- a/usertools/dpdk-devbind.py +++ b/usertools/dpdk-devbind.py @@ -161,12 +161,11 @@ def find_module(mod): # check using depmod try: - depmod_out = check_output(["modinfo", "-n", mod], - stderr=subprocess.STDOUT).lower() - if "error" not in depmod_out: - path = depmod_out.strip() - if exists(path): - return path + with open(os.devnull, "w") as fnull: + path = check_output(["modinfo", "-n", mod], stderr=fnull).strip() + + if path and exists(path): + return path except: # if modinfo can't find module, it fails, so continue pass -- 2.7.4