Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3860625pxv; Mon, 28 Jun 2021 14:59:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHrBWOoGvPD8u6izOqNeuCx4NLy09Wv1cvafKBTugbIqztdeJmOZqVT6mRw+a2YfZCV7FS X-Received: by 2002:a05:6402:1c82:: with SMTP id cy2mr3384466edb.324.1624917595261; Mon, 28 Jun 2021 14:59:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624917595; cv=none; d=google.com; s=arc-20160816; b=Jg3J+8exyE3ZLtZSRLoUYd8XM2TtH49azN3H5bUJKuJsK0KSL5/OMZ1RaLfJPcITFB bSuGkCBpnFQWmUJHbuMW0WxMAhB4LuEnRh3ob04eWFxu/cQD005rLZdWbBKJw/tqOFcd hV6z1/bEceW2E76EOBFZMdPM6k5lIydUtgyaun77tM4hY8epNx9YlNWtx/s03hKEDRkW ZDWLs4eLDhU5VqZZCnDb9HIOWUAKmPR0i0mKOIu1CvmzDspd559Y70Mm0LEku0b5BDyx ZnyRgolh8XSKISqaQh3+xCQvCczqmz+MpyOwZxgm80hK9VMpGT42BsAi9MAnjCHvhmGg P/kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=myO5ht1EmMhSPoGIF5xNJ6TKC0tB6UJ/urEkmgxROxI=; b=HF6hzcShL/Jx0X7XPWAAfn2D0I3dvsR2cuKMuZcQ0vIjeuiP1OQ7WTdCrcdXKC7uJx B3QKu9tFzLri5l7QpoBSxyKFm4llTBduwcTgEFvtjPY6+3KIgNR+RY5MlYhJnLkanuyc RAkQnjY0ZnB4b/gGxuCpV7oVipHGvin0KZu/erzI1L+gwkBMi1CLgx7zbnFqnFieWrQi wQ04ZtX5qcrwJZB2RBURKzQmAZLsU8TIOCF8qZBPPF5Jq8pM9caroxbOm8Ea5CHCa/iK VwNvBC1JUhKLLVsxfPh6SWtD3qDsr95SzefDkIJLVoPNPim8vezvZ+DICnVAw3Id8lkI eEXQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id la20si1303373ejc.685.2021.06.28.14.59.25; Mon, 28 Jun 2021 14:59:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237689AbhF1PUF (ORCPT + 99 others); Mon, 28 Jun 2021 11:20:05 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:38658 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232941AbhF1O4y (ORCPT ); Mon, 28 Jun 2021 10:56:54 -0400 Received: from 1.general.ppisati.uk.vpn ([10.172.193.134] helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lxseW-0005sL-Sk; Mon, 28 Jun 2021 14:54:24 +0000 From: Paolo Pisati To: "David S . Miller" , Jakub Kicinski , Shuah Khan 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 Message-Id: <20210628145424.69146-1-paolo.pisati@canonical.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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 --- 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