All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dpdk-devbind.py: remove module search corner cases
@ 2017-05-01 19:09 Mark Asselstine
  2017-05-01 22:01 ` Thomas Monjalon
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Asselstine @ 2017-05-01 19:09 UTC (permalink / raw)
  To: dev; +Cc: thomas

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 <mark.asselstine@windriver.com>
---
 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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] dpdk-devbind.py: remove module search corner cases
  2017-05-01 19:09 [PATCH] dpdk-devbind.py: remove module search corner cases Mark Asselstine
@ 2017-05-01 22:01 ` Thomas Monjalon
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Monjalon @ 2017-05-01 22:01 UTC (permalink / raw)
  To: Mark Asselstine; +Cc: dev

01/05/2017 21:09, Mark Asselstine:
> 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 <mark.asselstine@windriver.com>

Good explanation and good fix.

Applied, thanks and welcome

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-05-01 22:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-01 19:09 [PATCH] dpdk-devbind.py: remove module search corner cases Mark Asselstine
2017-05-01 22:01 ` Thomas Monjalon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.