From patchwork Mon Jul 13 17:55:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Saheed O. Bolarinwa" X-Patchwork-Id: 11660743 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 96DAE14DD for ; Mon, 13 Jul 2020 16:55:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7CCAC206F5 for ; Mon, 13 Jul 2020 16:55:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qmI/dKku" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729659AbgGMQzO (ORCPT ); Mon, 13 Jul 2020 12:55:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729969AbgGMQzN (ORCPT ); Mon, 13 Jul 2020 12:55:13 -0400 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CAE8C061755; Mon, 13 Jul 2020 09:55:13 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id by13so14266940edb.11; Mon, 13 Jul 2020 09:55:13 -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=236yoLO9rvFi7kFEaDT+jdNhQShh5zAyQTJD1cMNwbc=; b=qmI/dKkuGKWs1uJ/X+ORo2j9ZYWZLY//kGgOrJqvN0aGQHXouo9YDB4nmjhqfGS5HE w7TNx7OdD/HGeRKuN/8SUJOm/BYKXqm/oPoQDqXcvJrWQQCyGA2M16n9RvjaO+kfo7Mg vPGH++wf3L1TXs1DHBmVvhPRFmAFDdsoJZz6BPqAbYRpQDk9aHt20GC2FxkITx2TVBCA /2Y2Iz0OfTDCHMcXstLS1S96GW8SIkIfj0gVI9DD0VKL3DMNUdWO27amm2BoqL3uFH94 RSyexOquu8pAfOIGi1x4GhBae9z3c/MauTBf+xMYA5e8tncOHKWz9HEGhtvQN9D/oJAv PCkg== 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=236yoLO9rvFi7kFEaDT+jdNhQShh5zAyQTJD1cMNwbc=; b=TxkC1ukwDOApE2S2zSNAlLVBssK1iMxDwsmR8n56YSVuuLmSR5EcJSVC5qJK+NIF3R udrW2SfNJLlvZrUkFThu496iGsyvyUBL4pOF542QNqj46Ct8/fstw3MzBRQqaZXH9B+9 EOUVDbHh9ggUJjuqhOgCXYPCYkgLqTlMUDEBsiXdjaU9jifaCQ3khQa84Ofa1c4Lfy30 hoyPSXHeBXm2DfSyatAWyXXpyhMhgPPcI3oEzhJ1Pb5wuashdAMFK95ttV6qr+P0kIWy qodRFTpgUZfhgVD4HAIasHW/N7pK93okn84ulTyRp7YeZtESnbvTjXgCjYuxhdE901gU wsUA== X-Gm-Message-State: AOAM533MSAyoWMqgYIsN5fi/seFiB4/Qsmv2p/oqhV6N3w/NX3gWXyRn y2Tg7Yf/xC3CDjOFhK9Ttws= X-Google-Smtp-Source: ABdhPJzS8bGidfvYhEBX+Vxk3kFa37roPQ//u7I4H6NbrGfX2t/Lv7uDWvR+9xa8wn77M37ExBUJqw== X-Received: by 2002:a05:6402:b9b:: with SMTP id cf27mr368195edb.84.1594659312267; Mon, 13 Jul 2020 09:55:12 -0700 (PDT) Received: from net.saheed (54007186.dsl.pool.telekom.hu. [84.0.113.134]) by smtp.gmail.com with ESMTPSA id w3sm11838938edq.65.2020.07.13.09.55.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2020 09:55:11 -0700 (PDT) From: "Saheed O. Bolarinwa" To: skhan@linuxfoundation.org, linux-pci@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org, QCA ath9k Development , linux-wireless@vger.kernel.org, netdev@vger.kernel.org Cc: Bolarinwa Olayemi Saheed , Kalle Valo Subject: [PATCH 3/14 v3] ath9k: Check the return value of pcie_capability_read_*() Date: Mon, 13 Jul 2020 19:55:26 +0200 Message-Id: <20200713175529.29715-2-refactormyself@gmail.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <20200713175529.29715-1-refactormyself@gmail.com> References: <20200713175529.29715-1-refactormyself@gmail.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bolarinwa Olayemi Saheed On failure pcie_capability_read_dword() sets it's last parameter, val to 0. However, with Patch 14/14, 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 without changing the function's behaviour if the return value of pcie_capability_read_dword is checked to confirm success. Check the return value of pcie_capability_read_dword() to ensure success. Suggested-by: Bjorn Helgaas Signed-off-by: Bolarinwa Olayemi Saheed --- drivers/net/wireless/ath/ath9k/pci.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/ath/ath9k/pci.c b/drivers/net/wireless/ath/ath9k/pci.c index f3461b193c7a..cff9af3af38d 100644 --- a/drivers/net/wireless/ath/ath9k/pci.c +++ b/drivers/net/wireless/ath/ath9k/pci.c @@ -825,6 +825,7 @@ static void ath_pci_aspm_init(struct ath_common *common) struct pci_dev *pdev = to_pci_dev(sc->dev); struct pci_dev *parent; u16 aspm; + int ret; if (!ah->is_pciexpress) return; @@ -866,8 +867,8 @@ static void ath_pci_aspm_init(struct ath_common *common) if (AR_SREV_9462(ah)) pci_read_config_dword(pdev, 0x70c, &ah->config.aspm_l1_fix); - pcie_capability_read_word(parent, PCI_EXP_LNKCTL, &aspm); - if (aspm & (PCI_EXP_LNKCTL_ASPM_L0S | PCI_EXP_LNKCTL_ASPM_L1)) { + ret = pcie_capability_read_word(parent, PCI_EXP_LNKCTL, &aspm); + if (!ret && (aspm & (PCI_EXP_LNKCTL_ASPM_L0S | PCI_EXP_LNKCTL_ASPM_L1))) { ah->aspm_enabled = true; /* Initialize PCIe PM and SERDES registers. */ ath9k_hw_configpcipowersave(ah, false); From patchwork Mon Jul 13 17:55:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Saheed O. Bolarinwa" X-Patchwork-Id: 11660741 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 675D6722 for ; Mon, 13 Jul 2020 16:55:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4FCBB20773 for ; Mon, 13 Jul 2020 16:55:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NSPewnin" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730389AbgGMQz3 (ORCPT ); Mon, 13 Jul 2020 12:55:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730293AbgGMQzP (ORCPT ); Mon, 13 Jul 2020 12:55:15 -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 BF7B7C061755; Mon, 13 Jul 2020 09:55:14 -0700 (PDT) Received: by mail-ed1-x541.google.com with SMTP id dg28so14289441edb.3; Mon, 13 Jul 2020 09:55:14 -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=e583Pj41mbGa0akKyeW2rYwc3SOFBc4BRiRYVhykVn0=; b=NSPewnin+umq+Hpw1VWQZYiIMe8GpYsUXwfzptgWDWoPiRg5JdRkQnTxGPG5XIcKLi UUpNEzCE0J/2F+81HVw1NIlylHNjNmYp+qtI8ey59l45x6EqCxhfqzxJLFlE3ViR3tt4 zBgFSTsenkoT784l1whYtML/oIG5HU9WWWJbol4bUzzLcgUnuK4xRLw49BMrPrYf1CkA Jn3hbTiIT1KUEph4CzyOnMiLetZlrOxRM6l/pkEpJA0NtPVqY/sMvCdJVyBd8cwBBf92 GmQLYC2DxDBpG/6rydAcun+L5sogjQM9CykfTBM+Yux9ijI2LhF9iQWN1rXROIgt8JRC jKWw== 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=e583Pj41mbGa0akKyeW2rYwc3SOFBc4BRiRYVhykVn0=; b=Y5T7XbmRbFhwcPiKkHZEXRJ5hFHruyYt9oNxePjN0BLA5s/rkQVkI7I/TdoXbK5UEz 2Op5eeoGSecMFHbTq8LJDPY90kFj8MIO9hQs9tb6ngGSEe5+BVt21ys2tlDOXDd8CSpY nzSS8y30wQF1xtQ1euVsINiytnPxOkrZ7lWZdprawX5jasxmgvv8n0hBM0DDUV9K1t33 4QHxRL0PvNPCd34GTA5OWIetD9Q91QwsFOSug24fVPNotiQgs4uxL2Ijyhcs246ftkKl xruh/U/PktLm8YkgQH9xN+sAh2+gCp09lW9HrX7SOfqDWfCKHroyAZ64dlzLydhSoTnD b17w== X-Gm-Message-State: AOAM533dQ3qo8xg0uXSZJdQU5lRTWUkBGjlx13qHe/SLGlIZbHsWmbwz bIJ0joHUX7J56hR1MrEs6I4= X-Google-Smtp-Source: ABdhPJzFuefoL/4Rxcgaj8jw3dS3fKhP7a3GskQbwngqBSIPoeJgKGthmRz4CpvHrLMQeri2oZC1DQ== X-Received: by 2002:a05:6402:b86:: with SMTP id cf6mr358151edb.42.1594659313535; Mon, 13 Jul 2020 09:55:13 -0700 (PDT) Received: from net.saheed (54007186.dsl.pool.telekom.hu. [84.0.113.134]) by smtp.gmail.com with ESMTPSA id w3sm11838938edq.65.2020.07.13.09.55.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2020 09:55:13 -0700 (PDT) From: "Saheed O. Bolarinwa" To: skhan@linuxfoundation.org, linux-pci@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org, Stanislaw Gruszka , linux-wireless@vger.kernel.org, netdev@vger.kernel.org Cc: Bolarinwa Olayemi Saheed , Kalle Valo Subject: [PATCH 4/14 v3] iwlegacy: Check the return value of pcie_capability_read_*() Date: Mon, 13 Jul 2020 19:55:27 +0200 Message-Id: <20200713175529.29715-3-refactormyself@gmail.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <20200713175529.29715-1-refactormyself@gmail.com> References: <20200713175529.29715-1-refactormyself@gmail.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bolarinwa Olayemi Saheed On failure pcie_capability_read_dword() sets it's last parameter, val to 0. However, with Patch 14/14, 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 without changing the function's behaviour if the return value of pcie_capability_read_dword is checked to confirm success. Check the return value of pcie_capability_read_dword() to ensure success. Suggested-by: Bjorn Helgaas Signed-off-by: Bolarinwa Olayemi Saheed --- drivers/net/wireless/intel/iwlegacy/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/intel/iwlegacy/common.c b/drivers/net/wireless/intel/iwlegacy/common.c index 348c17ce72f5..f78e062df572 100644 --- a/drivers/net/wireless/intel/iwlegacy/common.c +++ b/drivers/net/wireless/intel/iwlegacy/common.c @@ -4286,8 +4286,8 @@ il_apm_init(struct il_priv *il) * power savings, even without L1. */ if (il->cfg->set_l0s) { - pcie_capability_read_word(il->pci_dev, PCI_EXP_LNKCTL, &lctl); - if (lctl & PCI_EXP_LNKCTL_ASPM_L1) { + ret = pcie_capability_read_word(il->pci_dev, PCI_EXP_LNKCTL, &lctl); + if (!ret && (lctl & PCI_EXP_LNKCTL_ASPM_L1)) { /* L1-ASPM enabled; disable(!) L0S */ il_set_bit(il, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED); From patchwork Mon Jul 13 17:55:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Saheed O. Bolarinwa" X-Patchwork-Id: 11660737 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7D865722 for ; Mon, 13 Jul 2020 16:55:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 658EC206F5 for ; Mon, 13 Jul 2020 16:55:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HmmxQ/aE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730330AbgGMQzR (ORCPT ); Mon, 13 Jul 2020 12:55:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730325AbgGMQzQ (ORCPT ); Mon, 13 Jul 2020 12:55:16 -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 E2A1CC061755; Mon, 13 Jul 2020 09:55:15 -0700 (PDT) Received: by mail-ed1-x541.google.com with SMTP id d18so14277287edv.6; Mon, 13 Jul 2020 09:55:15 -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=iiHt01yExxr+UGjzI6XflZ+uDY4MKkRXHZbIPXDUuRY=; b=HmmxQ/aEsuwnYmu7uvp6iPKhOMZAIHMXP42//F908Nkqa4MLYdR6vM0f8CaAYqWowF cmLlcXg6JpO6pxfq/D/zt1YR+ZwGTV4syUfrH+YTz6B1Fs4vVUcsGP19zyzOASXLQlmZ qTKgzZNYZoquze0LtCBNYu9CdDrzkE2u3ekNQis8W69z1bxrl9hJzhzv1GepBQWS873d gw2++hMdnjYAB3HOhDaTO0eEJ/h40zjf9peBORLPHgXxyloTyKyiPqbw9YGSUU9NprrK bMu4dxYW7BLe+/eTe3hwCtah6QY+qHfien1FLHGr9zVADP/vvGBpx56b4RcfHUG+cyQ5 6/bw== 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=iiHt01yExxr+UGjzI6XflZ+uDY4MKkRXHZbIPXDUuRY=; b=Ih8UPvzzHNrcy17DJmaMUJ1Y3SxO8ttDv/THiPQE7VeOvZoBZ7iZeoXNnzU6BPo+O0 VJ1dm28QyoRMCu7B/h3E9QqZYUWWaK/5RRpvuJJRiwXI1468LvqszfFhsqs+oYx31gRS xd/m58vmpZAL8q567UndpK+siXMaiFb1C3MYQ1vF58uB/ugRBrV0ynsLTKre+Zi+YioI 7b27SxgKp4Plh5DcirZgFMoe18N2/EvD2ehCZRHLR1uFFoGDys7CmK7ol7WXjz+OlIFn EvaOcDW8SO/5TJf5fix0hvGExqQvBiDF+Oq7nXjJ+0gxPHhAgp62EdaS7VJmSqMBTvOh Twcw== X-Gm-Message-State: AOAM532/+1xQokP3L/X4qqZiT1TTe8WWaK+HO5/e1vuF2cqtova3JNVx p3JOpYZsaMBhCYGSR3MMFI+JCLUeZr+TPA== X-Google-Smtp-Source: ABdhPJz2hbS/YAxk7ynpXEBxv0L7UVNCdcghPyy01UrXKtCfUacUfQIn8EVUfGf1smzuZiWEtLdarg== X-Received: by 2002:a05:6402:3099:: with SMTP id de25mr348700edb.228.1594659314697; Mon, 13 Jul 2020 09:55:14 -0700 (PDT) Received: from net.saheed (54007186.dsl.pool.telekom.hu. [84.0.113.134]) by smtp.gmail.com with ESMTPSA id w3sm11838938edq.65.2020.07.13.09.55.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2020 09:55:14 -0700 (PDT) From: "Saheed O. Bolarinwa" To: skhan@linuxfoundation.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org Cc: Bolarinwa Olayemi Saheed Subject: [PATCH 8/14 v3] PCI/ACPI: Check the return value of pcie_capability_read_*() Date: Mon, 13 Jul 2020 19:55:28 +0200 Message-Id: <20200713175529.29715-4-refactormyself@gmail.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <20200713175529.29715-1-refactormyself@gmail.com> References: <20200713175529.29715-1-refactormyself@gmail.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bolarinwa Olayemi Saheed On failure pcie_capability_read_dword() sets it's last parameter, val to 0. However, with Patch 14/14, 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 Acked-by: Rafael J. Wysocki --- drivers/pci/pci-acpi.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c index 7224b1e5f2a8..39eb816bc3b8 100644 --- a/drivers/pci/pci-acpi.c +++ b/drivers/pci/pci-acpi.c @@ -248,12 +248,13 @@ static bool pcie_root_rcb_set(struct pci_dev *dev) { struct pci_dev *rp = pcie_find_root_port(dev); u16 lnkctl; + int ret; if (!rp) return false; - pcie_capability_read_word(rp, PCI_EXP_LNKCTL, &lnkctl); - if (lnkctl & PCI_EXP_LNKCTL_RCB) + ret = pcie_capability_read_word(rp, PCI_EXP_LNKCTL, &lnkctl); + if (!ret && (lnkctl & PCI_EXP_LNKCTL_RCB)) return true; return false; @@ -792,12 +793,13 @@ bool pciehp_is_native(struct pci_dev *bridge) { const struct pci_host_bridge *host; u32 slot_cap; + int ret; if (!IS_ENABLED(CONFIG_HOTPLUG_PCI_PCIE)) return false; - pcie_capability_read_dword(bridge, PCI_EXP_SLTCAP, &slot_cap); - if (!(slot_cap & PCI_EXP_SLTCAP_HPC)) + ret = pcie_capability_read_dword(bridge, PCI_EXP_SLTCAP, &slot_cap); + if (ret || !(slot_cap & PCI_EXP_SLTCAP_HPC)) return false; if (pcie_ports_native) From patchwork Mon Jul 13 17:55:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Saheed O. Bolarinwa" X-Patchwork-Id: 11660733 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E8FCF14DD for ; Mon, 13 Jul 2020 16:55:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CF79720773 for ; Mon, 13 Jul 2020 16:55:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QThq7T/N" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730354AbgGMQzT (ORCPT ); Mon, 13 Jul 2020 12:55:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730343AbgGMQzR (ORCPT ); Mon, 13 Jul 2020 12:55:17 -0400 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88B9AC061755; Mon, 13 Jul 2020 09:55:17 -0700 (PDT) Received: by mail-ed1-x542.google.com with SMTP id z17so14273825edr.9; Mon, 13 Jul 2020 09:55:17 -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=Vg5seoeyahxUOJ1a2of2OSXbNHc8+N6IhRiLy4XR8Ps=; b=QThq7T/NhE4spupA48w9flKBPIUZMsJ+uy1wChEjqmd9cLUhJNeozt9BNv1EslTKul 9FzUYVh1psv92TVnmY05kmXxx7YOjo4zsDzZUATn9e4zIhaa/IU/l64wBzjWvrwDbAdT yMVtRLi35HfG89vS3VWmX51PcL78Kumuk1a4Y+mb2X5zojZOcrMRGnHmOxMBpNMDphyn WM6skKGt7eauq9PMF4fMY/WlqUw991iJ1Ytz1rk4085GlJxA7KXFCo39uIxgjXQ9fuJN 3z5H1aRueRaa67gizAbiKT/8yQ6CvE9P5qTMm1ibl2NWyp9eZcuTPcv+4+0VHPs7z+dy 9v1Q== 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=Vg5seoeyahxUOJ1a2of2OSXbNHc8+N6IhRiLy4XR8Ps=; b=p9vjV2MKRvlqajgS93jCup4a4AxeGVHwFFW7YNsz3qfg6oMFr8TqULjK49VgeYZIeV 3zVorZouWzQyOnQbSOmxf5I2j0IcMwU6RUmToHdmkmfxBNb0K1e5qu2HJVj4ncagDN6Y NUn5MP72QBQ1NxMHk2p4qNLHmun/H/liXRM6WJR+VxUV/8SkS4kha7gmalUtcqIzXvyl pwn9oRMz0QpojhV1/zFU3M0Wz+wA9jbgom4P7FGMdTLdpSwKDCK/eICWV2+YXtdSkkhW ak4iOEPN8B9Pqvw7d+dNXZhGd5erxl9R3yaiPF+rmGQiuIm0zfPERr+x7zxrzA7WinL7 5RzQ== X-Gm-Message-State: AOAM532YEcQPprq+ll+v4y50QS9T7QBXFhDLJd7CT3QNAG960gK5QsFh YHT3HZcMG2dzaOCpOGn0izM= X-Google-Smtp-Source: ABdhPJwiuJGYBhFGQzVTlihXWfzHv/j6TtpsUC2ukWbQvIDZs82x6qtdrhI4g0KTxQkpdk5UBwbo4Q== X-Received: by 2002:aa7:d58c:: with SMTP id r12mr365600edq.160.1594659316271; Mon, 13 Jul 2020 09:55:16 -0700 (PDT) Received: from net.saheed (54007186.dsl.pool.telekom.hu. [84.0.113.134]) by smtp.gmail.com with ESMTPSA id w3sm11838938edq.65.2020.07.13.09.55.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2020 09:55:15 -0700 (PDT) From: "Saheed O. Bolarinwa" To: skhan@linuxfoundation.org, linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org Cc: Bolarinwa Olayemi Saheed Subject: [PATCH 12/14 v3] PCI/AER: Check the return value of pcie_capability_read_*() Date: Mon, 13 Jul 2020 19:55:29 +0200 Message-Id: <20200713175529.29715-5-refactormyself@gmail.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <20200713175529.29715-1-refactormyself@gmail.com> References: <20200713175529.29715-1-refactormyself@gmail.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bolarinwa Olayemi Saheed On failure pcie_capability_read_dword() sets it's last parameter, val to 0. However, with Patch 14/14, 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/pcie/aer.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c index 3acf56683915..f4beb47c622c 100644 --- a/drivers/pci/pcie/aer.c +++ b/drivers/pci/pcie/aer.c @@ -800,6 +800,7 @@ static bool is_error_source(struct pci_dev *dev, struct aer_err_info *e_info) int aer = dev->aer_cap; u32 status, mask; u16 reg16; + int ret; /* * When bus id is equal to 0, it might be a bad id @@ -828,8 +829,8 @@ static bool is_error_source(struct pci_dev *dev, struct aer_err_info *e_info) return false; /* Check if AER is enabled */ - pcie_capability_read_word(dev, PCI_EXP_DEVCTL, ®16); - if (!(reg16 & PCI_EXP_AER_FLAGS)) + ret = pcie_capability_read_word(dev, PCI_EXP_DEVCTL, ®16); + if (ret || !(reg16 & PCI_EXP_AER_FLAGS)) return false; if (!aer)