diff options
author | Paolo Pisati <paolo.pisati@canonical.com> | 2021-06-28 16:54:24 +0200 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2021-06-28 16:14:38 -0700 |
commit | a118ff661889ecee3ca90f8125bad8fb5bbc07d5 (patch) | |
tree | 18db590479ca5f90a8e181b91ecd65e6cb66e526 | |
parent | b856150c8098f12996ee81c3ab2a65adbaeeb3ec (diff) | |
download | linux-stable-a118ff661889ecee3ca90f8125bad8fb5bbc07d5.tar.gz linux-stable-a118ff661889ecee3ca90f8125bad8fb5bbc07d5.tar.bz2 linux-stable-a118ff661889ecee3ca90f8125bad8fb5bbc07d5.zip |
selftests: net: devlink_port_split: check devlink returned an element before dereferencing it
And thus avoid a Python stacktrace:
~/linux/tools/testing/selftests/net$ ./devlink_port_split.py
Traceback (most recent call last):
File "/home/linux/tools/testing/selftests/net/./devlink_port_split.py",
line 277, in <module> main()
File "/home/linux/tools/testing/selftests/net/./devlink_port_split.py",
line 242, in main
dev = list(devs.keys())[0]
IndexError: list index out of range
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rwxr-xr-x | tools/testing/selftests/net/devlink_port_split.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/tools/testing/selftests/net/devlink_port_split.py b/tools/testing/selftests/net/devlink_port_split.py index 834066d465fc..d162915311fd 100755 --- a/tools/testing/selftests/net/devlink_port_split.py +++ b/tools/testing/selftests/net/devlink_port_split.py @@ -239,6 +239,9 @@ def main(cmdline=None): assert stderr == "" devs = json.loads(stdout)['dev'] + if len(devs.keys()) == 0: + print("no devlink device found") + sys.exit(1) dev = list(devs.keys())[0] cmd = "devlink dev show %s" % dev |