Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp61297ybt; Tue, 7 Jul 2020 16:05:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSy9IZj+3Ptgb3tVQp1o3ewoNT+NWNSumqlRaN2N/Yiu9v8OYvw/3PEo9d/K5MlqLYyxgr X-Received: by 2002:a17:906:46cd:: with SMTP id k13mr48332781ejs.312.1594163150642; Tue, 07 Jul 2020 16:05:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594163150; cv=none; d=google.com; s=arc-20160816; b=u86mOMWVchmIUGEAYg2krEkQ2rkq5R0U0o4iqLLlCjfFBrobfxrXhQ6fppFHpi++Y8 hJb0cxOzrkoc/i8R3HystVd3cMiha2Q5Kdrmrv4P2q5kiJjKaJWJsF+JEeBnMu1PY4rl eTagyeEXO+Y1ncsVrzSzpwldvdVFAR3CtlXvCNzGA2RCD2vEmCQvR3P8mh/db5MyK+jT rG3HI88NH0tL9wZ3BpMsGTyHlH/xebp/H5YE2CP7GerqQ8Xetgxytn30+X+K9TpoCoGe EMp1hc1JdUxv2/gLeAQ/pJdzzDxcxW4zYtjU5l4XwGLfsUecgPIy2sfiWHf9Q+U9eKiL wbGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=WYmkLemsj0FXEGb5mTOcJF4Cv+pMmXhpwMJRkdTJQ+I=; b=vJGuwvE0jLV0wuazcp/UsIqgG8dnlPa5bjoXb66N+4LNNkHFgTzepy502IUWGdIgXU WDYdH0jp1FZD5QwAsMT9qWzOhDsRtubPo17l3k2GjMSlwTkobkN7KoV9Bmoa3jtWlGVB EFaWNiEHZZWEeOnxqvM+euzqRbev+D7188a4heD5p7wSkllH+gXP6IRcYMrW1GyHYN7v ll7uQCRkBxL5e2IBs1C7Y+N5xbFaVeH57BQL1cGbGSTL3Zf1Y7GAaGQV2hX0nzF6gnB6 QIuXmKwGAaqB/unwuaSeNmpWGvSBf+VMsSYrPY8Vuquvffe0WVHqqbHq9w6tqDkLhRGX FaWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pPoXd4O9; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id me25si16078163ejb.164.2020.07.07.16.05.26; Tue, 07 Jul 2020 16:05:50 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pPoXd4O9; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729340AbgGGXEM (ORCPT + 99 others); Tue, 7 Jul 2020 19:04:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729196AbgGGXDz (ORCPT ); Tue, 7 Jul 2020 19:03:55 -0400 Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [IPv6:2a00:1450:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCFFBC061755; Tue, 7 Jul 2020 16:03:54 -0700 (PDT) Received: by mail-ed1-x541.google.com with SMTP id g20so39883146edm.4; Tue, 07 Jul 2020 16:03:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WYmkLemsj0FXEGb5mTOcJF4Cv+pMmXhpwMJRkdTJQ+I=; b=pPoXd4O90Pe0JE7GI4II2rpi0aThostwrOBB/3Xj7V8yTklREErqFL4j+DJeyfoMIe 9NN1WaPwmiBhPiaGdg9pn9twLJOJAKJj++jTXX2M1zmG+WzdSDIWR5EdYuJY/L3cg1px EbCNuf1trgJHv+wpAsy8EB5qIs/Og0NabA2BsJSeeDS2PTlFcgW363xv7h2pCA+D57OK JqxHr6hs1nUrmN+/zDDIkfW7urnh1X+J6TYVoqxOfHAMF0Wpbj4SWDTaO7dNksmfXhCN sz0dC644pBVzWjcFJslNiA3iAFNKtPydZ6lJfDPhAXXdLbjm/3ZviQjX+fac+UCt1eU4 Phow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WYmkLemsj0FXEGb5mTOcJF4Cv+pMmXhpwMJRkdTJQ+I=; b=dtSsUo0PbjLRB/V86RbulPFP7gAoBdNY3ksVjp6v6ST1IM6LBK7FarzZSfNXHQQ++t Fu5AeX1L9jS4rRb//mrYH5GLjsYhxIcFRHzPnVczvT+rOFG9mD7mTdpLkyPhkpJzcIAU LrIMkwMlNOeWZRoErvXRz7gZ9i5EheeAWAWn7BbwCKrSRhHSTTDLtv5TuCAwCiaYNq+G GZikyLjyAjvlUOsSAL1txEuldEG9smoBrsJfhslfL3AN0p0NDY3wNq0hHMeLDEcCtxlA W4mYEKfX6t5gLL6r6GG15Iq/fNk6M8Ruhu1008Qmtm38X2y8kdbWukHg/Ux65Oe+FxzN 3SDA== X-Gm-Message-State: AOAM533kYsgnpvUCbckBdgSb0NCB4Bi7m2PHjNoPRzZmN+ycMf9IxWb5 IY/fN3DQGK0fJiMXN6zTlsY= X-Received: by 2002:aa7:cfc8:: with SMTP id r8mr29122380edy.125.1594163033678; Tue, 07 Jul 2020 16:03:53 -0700 (PDT) Received: from net.saheed (54007186.dsl.pool.telekom.hu. [84.0.113.134]) by smtp.gmail.com with ESMTPSA id f10sm27096310edx.5.2020.07.07.16.03.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 16:03:53 -0700 (PDT) From: Saheed Olayemi Bolarinwa To: helgaas@kernel.org Cc: Bolarinwa Olayemi Saheed , bjorn@helgaas.com, skhan@linuxfoundation.org, linux-pci@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org Subject: [PATCH 9/13] PCI: Check return value of pcie_capability_read_*() Date: Wed, 8 Jul 2020 00:03:20 +0200 Message-Id: <20200707220324.8425-10-refactormyself@gmail.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <20200707220324.8425-1-refactormyself@gmail.com> References: <20200707220324.8425-1-refactormyself@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bolarinwa Olayemi Saheed On failure pcie_capability_read_dword() sets it's last parameter, val to 0. However, with Patch 13/13, it is possible that val is set to ~0 on failure. This would introduce a bug because (x & x) == (~0 & x). This bug can be avoided if the return value of pcie_capability_read_word is checked to confirm success. Check the return value of pcie_capability_read_word() to ensure success. Suggested-by: Bjorn Helgaas Signed-off-by: Bolarinwa Olayemi Saheed --- drivers/pci/probe.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 2f66988cea25..3c87a8a1d4b5 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1121,10 +1121,11 @@ EXPORT_SYMBOL(pci_add_new_bus); static void pci_enable_crs(struct pci_dev *pdev) { u16 root_cap = 0; + int ret; /* Enable CRS Software Visibility if supported */ - pcie_capability_read_word(pdev, PCI_EXP_RTCAP, &root_cap); - if (root_cap & PCI_EXP_RTCAP_CRSVIS) + ret = pcie_capability_read_word(pdev, PCI_EXP_RTCAP, &root_cap); + if (!ret && (root_cap & PCI_EXP_RTCAP_CRSVIS)) pcie_capability_set_word(pdev, PCI_EXP_RTCTL, PCI_EXP_RTCTL_CRSSVE); } @@ -1519,9 +1520,10 @@ void set_pcie_port_type(struct pci_dev *pdev) void set_pcie_hotplug_bridge(struct pci_dev *pdev) { u32 reg32; + int ret; - pcie_capability_read_dword(pdev, PCI_EXP_SLTCAP, ®32); - if (reg32 & PCI_EXP_SLTCAP_HPC) + ret = pcie_capability_read_dword(pdev, PCI_EXP_SLTCAP, ®32); + if (!ret && (reg32 & PCI_EXP_SLTCAP_HPC)) pdev->is_hotplug_bridge = 1; } @@ -2057,10 +2059,11 @@ int pci_configure_extended_tags(struct pci_dev *dev, void *ign) bool pcie_relaxed_ordering_enabled(struct pci_dev *dev) { u16 v; + int ret; - pcie_capability_read_word(dev, PCI_EXP_DEVCTL, &v); + ret = pcie_capability_read_word(dev, PCI_EXP_DEVCTL, &v); - return !!(v & PCI_EXP_DEVCTL_RELAX_EN); + return (!ret && !!(v & PCI_EXP_DEVCTL_RELAX_EN)); } EXPORT_SYMBOL(pcie_relaxed_ordering_enabled); @@ -2096,16 +2099,17 @@ static void pci_configure_ltr(struct pci_dev *dev) struct pci_host_bridge *host = pci_find_host_bridge(dev->bus); struct pci_dev *bridge; u32 cap, ctl; + int ret; if (!pci_is_pcie(dev)) return; - pcie_capability_read_dword(dev, PCI_EXP_DEVCAP2, &cap); - if (!(cap & PCI_EXP_DEVCAP2_LTR)) + ret = pcie_capability_read_dword(dev, PCI_EXP_DEVCAP2, &cap); + if (ret || !(cap & PCI_EXP_DEVCAP2_LTR)) return; - pcie_capability_read_dword(dev, PCI_EXP_DEVCTL2, &ctl); - if (ctl & PCI_EXP_DEVCTL2_LTR_EN) { + ret = pcie_capability_read_dword(dev, PCI_EXP_DEVCTL2, &ctl); + if (!ret && (ctl & PCI_EXP_DEVCTL2_LTR_EN)) { if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT) { dev->ltr_path = 1; return; @@ -2142,12 +2146,13 @@ static void pci_configure_eetlp_prefix(struct pci_dev *dev) struct pci_dev *bridge; int pcie_type; u32 cap; + int ret; if (!pci_is_pcie(dev)) return; - pcie_capability_read_dword(dev, PCI_EXP_DEVCAP2, &cap); - if (!(cap & PCI_EXP_DEVCAP2_EE_PREFIX)) + ret = pcie_capability_read_dword(dev, PCI_EXP_DEVCAP2, &cap); + if (ret || !(cap & PCI_EXP_DEVCAP2_EE_PREFIX)) return; pcie_type = pci_pcie_type(dev); -- 2.18.2