From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E4821C433EF for ; Thu, 21 Apr 2022 16:14:19 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B0EAB83EDD; Thu, 21 Apr 2022 18:12:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="XV8OjuFR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 23EF783EAF; Thu, 21 Apr 2022 18:11:59 +0200 (CEST) Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 22BDE83E66 for ; Thu, 21 Apr 2022 18:11:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=3SoJhYgYKBu0PhRjaaVddVaT.Rdbj-QddiaXhih.STcm.ST@flex--ascull.bounces.google.com Received: by mail-wm1-x349.google.com with SMTP id p31-20020a05600c1d9f00b0038ed0964a90so2590523wms.4 for ; Thu, 21 Apr 2022 09:11:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=l3ZB5EjqU+Lw1g7rs5TGb6RN4CAdY6wpS9XuSfxq1bg=; b=XV8OjuFRdhlm5R1t7oIG4PerGY5hS5R8GmoZx3DWFrYd/b5TJVFiajgHFPZGiKd5l9 HlDuEbq+QRwHO3qQKMpsBwN/RLFB/X0f+T2Qvh00IIMWLL7UoMQduzGz7glpmEgqXDtB oz6RQMnBgqf6UoZJK5jgOi/GJMgXOi1qsm2JzhH3dzry/whpT/9Aq0VzduOpNmQUMY+6 DzQGkz+ZVIufgDHhunJ9xU0TlpeLYIyz1uOY7KAhvAJDijuoMobtMK5R+kFShnYTx4+F x+EZxJ15hQ2Rq5jP3tKs37wW4phGr3q0TeGsrrp8cg4vrwE/WnZnx1HWmK/Ti5kPclAZ skJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=l3ZB5EjqU+Lw1g7rs5TGb6RN4CAdY6wpS9XuSfxq1bg=; b=sClNfeZCI1N+tjsnegMMTtYqVHqtjAdnhL+iE5bwju6SN4dIU66xyHMsNyORcApx4k qkT4nIQZzJOHuD4zYrUF9AO74HVjaLLI7RQj7W53Im7TaLXEgcSCi8xWdbcwdUhqSghN hg2oa+C64pDA0ZzakC5XNRhQ3huv/WJ5gW3e9TaLVSgUHs1OFwIfUop+/NP+jSZa4Att SFtJDNShuNNN/hOG7ynE8WK/UUgmuptzVB1kWEnBpp/eMvjIogFfGQO+8rWItGMrUrv8 JPVkQHoYkOhezxprf0fCos4rVH+ahB9y28Sp7L8jEWgVyN0B4vDbWMaDb/mcjKZ9W+Nt CiDg== X-Gm-Message-State: AOAM532XRaZnBriKyzqiL28A2Y3Z/1/61U/cia73kE/urf0WowpUxXbk wMhEQx186Zhg+HDqegStzxw1YpVdF/SSFuhhd6Lg7Hxt5JZT5PyDeVw7wNjT/THJKIlmVAJO3IM yMKgKNejJ8WKMWuHz1bbnZG7LFBFhq0V8W44l4RuD6rC/D0krvuSwxuiSmL8= X-Google-Smtp-Source: ABdhPJyOzoBZ0KgKqEi7sB/HHYM59t7shEx943Iom/rLl9vlB7KMo/5qNslfsZbxShBgNPFsTW+PzU1u80s= X-Received: from ascull.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1510]) (user=ascull job=sendgmr) by 2002:a7b:c0d5:0:b0:38e:ca29:f40 with SMTP id s21-20020a7bc0d5000000b0038eca290f40mr71705wmh.205.1650557514746; Thu, 21 Apr 2022 09:11:54 -0700 (PDT) Date: Thu, 21 Apr 2022 16:11:14 +0000 In-Reply-To: <20220421161116.1202023-1-ascull@google.com> Message-Id: <20220421161116.1202023-17-ascull@google.com> Mime-Version: 1.0 References: <20220421161116.1202023-1-ascull@google.com> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog Subject: [PATCH v3 16/18] virtio: pci: Check virtio configs are mapped From: Andrew Scull To: u-boot@lists.denx.de Cc: sjg@chromium.org, bmeng.cn@gmail.com, trini@konsulko.com, Andrew Scull Content-Type: text/plain; charset="UTF-8" X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Prepare for calls to `virtio_pci_map_capability()` failing by returning NULL on error. If this happens, later accesses to the pointers would be unsafe so cause the probe to fail if such an error occurs. Signed-off-by: Andrew Scull Reviewed-by: Bin Meng --- drivers/virtio/virtio_pci_modern.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c index bf92d9d3ba..f1e64a3438 100644 --- a/drivers/virtio/virtio_pci_modern.c +++ b/drivers/virtio/virtio_pci_modern.c @@ -533,7 +533,19 @@ static int virtio_pci_probe(struct udevice *udev) return -EINVAL; } + /* Map configuration structures */ + priv->common = virtio_pci_map_capability(udev, &common_cap); + if (!priv->common) { + printf("(%s): could not map common config\n", udev->name); + return -EINVAL; + } + priv->notify_len = notify_cap.length; + priv->notify_base = virtio_pci_map_capability(udev, ¬ify_cap); + if (!priv->notify_base) { + printf("(%s): could not map notify config\n", udev->name); + return -EINVAL; + } /* * Device capability is only mandatory for devices that have @@ -545,11 +557,13 @@ static int virtio_pci_probe(struct udevice *udev) if (device) { priv->device_len = device_cap.length; priv->device = virtio_pci_map_capability(udev, &device_cap); + if (!priv->device) { + printf("(%s): could not map device config\n", + udev->name); + return -EINVAL; + } } - /* Map configuration structures */ - priv->common = virtio_pci_map_capability(udev, &common_cap); - priv->notify_base = virtio_pci_map_capability(udev, ¬ify_cap); debug("(%p): common @ %p, notify base @ %p, device @ %p\n", udev, priv->common, priv->notify_base, priv->device); -- 2.36.0.rc2.479.g8af0fa9b8e-goog