linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Pisati <paolo.pisati@canonical.com>
To: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Shuah Khan <shuah@kernel.org>
Cc: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] selftests: net: devlink_port_split: check devlink returned an element before dereferencing it
Date: Mon, 28 Jun 2021 16:54:24 +0200	[thread overview]
Message-ID: <20210628145424.69146-1-paolo.pisati@canonical.com> (raw)

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>
---
 tools/testing/selftests/net/devlink_port_split.py | 3 +++
 1 file changed, 3 insertions(+)

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
-- 
2.30.2


             reply	other threads:[~2021-06-28 15:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-28 14:54 Paolo Pisati [this message]
2021-06-28 23:20 ` [PATCH] selftests: net: devlink_port_split: check devlink returned an element before dereferencing it patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly 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=20210628145424.69146-1-paolo.pisati@canonical.com \
    --to=paolo.pisati@canonical.com \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=shuah@kernel.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).