From patchwork Fri Jul 31 11:02: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: 11694749 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 6820F722 for ; Fri, 31 Jul 2020 12:02:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5036922CA1 for ; Fri, 31 Jul 2020 12:02:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JcMW1Amz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732998AbgGaMCV (ORCPT ); Fri, 31 Jul 2020 08:02:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732699AbgGaMCT (ORCPT ); Fri, 31 Jul 2020 08:02:19 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91E9DC061574; Fri, 31 Jul 2020 05:02:19 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id c2so16336192edx.8; Fri, 31 Jul 2020 05:02:19 -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=amVhr7R4Tl+AZRhIhKHpLA6uHviyCSc4sbl+N98Jdpg=; b=JcMW1AmzuSS8oG65Inbid1bJUW/hbncZI7QS2d5UfMrtraGXnzfDKeDWUDIhuDP/6T a5oy1TmPN7ZBWRpPUELAvSc5ujNSi1+DihJnVMqL9vW2Zx+Gqyawvb1ZEH1Jfv3gEIrJ Lb33FgO9+8s5fiMLgtNRSIsBQ/8O1duwSGT7dVS7uZoRDhjo39sJfhzJWtn4xdYsjJ2u Ap3vuoboz/YeojnQZcGlmicmKam1fnTIigSdb5tkXlt1czDa2nbdWRmVzLSyOYzUiz0Q HEQsp232s4YkFDK8tN4PaxGlzYevBgaH5JeG75wkyNZjaVXbkGPtcdIWaK1VnBc5/gUK kRUw== 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=amVhr7R4Tl+AZRhIhKHpLA6uHviyCSc4sbl+N98Jdpg=; b=DspcxHkPfmfOZ5+wRVzzP3+uwFaeS/X7NMqCQKlIvFR0iXTeWRTNLqloD8mB/VgNzx 8PWCxAjXL9YmuIcaGdPLV05LAf8RrDiw19ybmO57vC6jq5Ych2Uc30oevaZJdkaXuAfA 17n7x2rbvvUO+oniTpsaOwTPQAtfPLZozKWgux8bxTAx7LCwIUXBrmxWeRz95L7G7G7y rrvR2BFP89IgMl66bjc2FORjZS4Xh7r8yLezEmi/2BcxaJ43VhlEO9ni9hNyBoX9uzDQ bKXgpqzdL8viiNB3hOGqjXf//Oego4Gr5avNoOWLO5BgK2rIpiTB8RWUF0pRtCbRGK2T PMFA== X-Gm-Message-State: AOAM533ExnG7rzIow8/Vd7aWCLHtKLo+OY15WcCo91NEUjYHTSvX50z2 dv8RVyOxq5JsgppEs4S3pfY= X-Google-Smtp-Source: ABdhPJxxcaYV0fL7ANNAzpxeHZXM0MM7VCpGGNBUD6uol8RNcQxADNTtg7/dBuH2xZETfFkTuu3WUQ== X-Received: by 2002:aa7:ce90:: with SMTP id y16mr3597463edv.325.1596196938310; Fri, 31 Jul 2020 05:02:18 -0700 (PDT) Received: from net.saheed (95C84E0A.dsl.pool.telekom.hu. [149.200.78.10]) by smtp.gmail.com with ESMTPSA id j5sm9091734ejk.87.2020.07.31.05.02.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 05:02:17 -0700 (PDT) From: "Saheed O. Bolarinwa" To: helgaas@kernel.org, Mike Marciniszyn , Dennis Dalessandro , Doug Ledford , Jason Gunthorpe Cc: "Saheed O. Bolarinwa" , bjorn@helgaas.com, skhan@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org Subject: [PATCH v4 01/12] IB/hfi1: Check if pcie_capability_read_*() reads ~0 Date: Fri, 31 Jul 2020 13:02:29 +0200 Message-Id: <20200731110240.98326-2-refactormyself@gmail.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20200731110240.98326-1-refactormyself@gmail.com> References: <20200731110240.98326-1-refactormyself@gmail.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On failure pcie_capability_read_dword() sets it's last parameter, val to 0. In this case dn and up will be 0, so aspm_hw_l1_supported() will return false. However, with Patch 12/12, it is possible that val is set to ~0 on failure. This would introduce a bug because (x & x) == (~0 & x). So with dn and up being 0x02, a true value is return when the read has actually failed. Since, the value ~0 is invalid here, Reset dn and up to 0 when a value of ~0 is read into them, this ensures false is returned on failure in this case. Suggested-by: Bjorn Helgaas Signed-off-by: Saheed O. Bolarinwa --- drivers/infiniband/hw/hfi1/aspm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/aspm.c b/drivers/infiniband/hw/hfi1/aspm.c index a3c53be4072c..9605b2145d19 100644 --- a/drivers/infiniband/hw/hfi1/aspm.c +++ b/drivers/infiniband/hw/hfi1/aspm.c @@ -33,13 +33,13 @@ static bool aspm_hw_l1_supported(struct hfi1_devdata *dd) return false; pcie_capability_read_dword(dd->pcidev, PCI_EXP_LNKCAP, &dn); - dn = ASPM_L1_SUPPORTED(dn); + dn = (dn == (u32)~0) ? 0 : ASPM_L1_SUPPORTED(dn); pcie_capability_read_dword(parent, PCI_EXP_LNKCAP, &up); - up = ASPM_L1_SUPPORTED(up); + up = (up == (u32)~0) ? 0 : ASPM_L1_SUPPORTED(up); /* ASPM works on A-step but is reported as not supported */ - return (!!dn || is_ax(dd)) && !!up; + return (dn || is_ax(dd)) && up; } /* Set L1 entrance latency for slower entry to L1 */ From patchwork Fri Jul 31 11:02:30 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: 11694751 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 8414814E3 for ; Fri, 31 Jul 2020 12:02:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6D17822D02 for ; Fri, 31 Jul 2020 12:02:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tdc87K9U" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732944AbgGaMCv (ORCPT ); Fri, 31 Jul 2020 08:02:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733001AbgGaMCV (ORCPT ); Fri, 31 Jul 2020 08:02:21 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05544C061574; Fri, 31 Jul 2020 05:02:21 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id bo3so8536415ejb.11; Fri, 31 Jul 2020 05:02:20 -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=ml221r4dHqXe07i3xfLOyBkeN0U7ADgIKojP7DQw/XU=; b=tdc87K9UnCJy6h8rTMzof2JLZE4gpUzsMej7iiUfVOUd8Id5xNJOXDAFSfsuz1w6u7 iPtFsNJnx1SkMUgFfvLUPtv9cu83vKOHYyRXtSmX7KgJcVnPQ3gnhE8Vn7frgHaIxoVi Z+sknEjd13Z6IBnP0Jr1Gxd6tF5MYqxOo+hJMYp26pN1GTyaYHyecoyhHHtGfC0VobdR mBKxZ07cIazEDKChb+I7ckeC2rc+uHvtBAkpedhjsjR469MF4Evszk9aoUuX/w/fp92p VaLu2ghSiNVcmXKdZDtlEE5Eunx6Vqus4obfwNnNzChqQ/gvK3jUU6SEn0bMJjdZoz9a s00A== 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=ml221r4dHqXe07i3xfLOyBkeN0U7ADgIKojP7DQw/XU=; b=VO/ZHz++ggkO+pZzm9eTS5b2vfxdGXT75PU0zHBT5WIBFppuBmqUp8V9qnlTQI/VVJ nv7PJUUQeEzZsET6ZeSiK7uiP14M+ggjfBA0y7yqEnkT9CqavTltXov8uzwQGaPEeF2N UqS1q5e7iL6Z3H69POQO0esEl54ZQKeRafBIn6Sg8RLu/9r6gYv/nZle4vJWdHUgbQCP BJvJbEIIjMqTBerXA3Zvit58XF9LGFvMezdg/Cqc6Ar1N9wwbzs6sKeNxbob/USMMF/5 c31nvKEV85k2QHUptBkyRJzFzXoy6TJqrOxkX26fdDB4eiBsHslvBSs0aGMj+aDVk0s5 cs8Q== X-Gm-Message-State: AOAM533jhp02Z7kl5ZeUzfHPAv465O7ZvSo0NDgiHpFKKKRWtKAazGcq EiD1y+0AVRUV25hdIZrueB+a7UDtjUwS2g== X-Google-Smtp-Source: ABdhPJzVmRwWuzV+in/VwaHSzymsIW0npTezXTXxbvP7G3I49+S4RYZeWtmVO3+jrmVNC2IMOL/qcQ== X-Received: by 2002:a17:906:a94b:: with SMTP id hh11mr3659252ejb.104.1596196939763; Fri, 31 Jul 2020 05:02:19 -0700 (PDT) Received: from net.saheed (95C84E0A.dsl.pool.telekom.hu. [149.200.78.10]) by smtp.gmail.com with ESMTPSA id j5sm9091734ejk.87.2020.07.31.05.02.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 05:02:19 -0700 (PDT) From: "Saheed O. Bolarinwa" To: helgaas@kernel.org, Arnd Bergmann , Greg Kroah-Hartman Cc: "Saheed O. Bolarinwa" , bjorn@helgaas.com, skhan@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 02/12] misc: rtsx: Check if pcie_capability_read_*() reads ~0 Date: Fri, 31 Jul 2020 13:02:30 +0200 Message-Id: <20200731110240.98326-3-refactormyself@gmail.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20200731110240.98326-1-refactormyself@gmail.com> References: <20200731110240.98326-1-refactormyself@gmail.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On failure pcie_capability_read_word() sets it's last parameter, val to 0. In which case (val & PCI_EXP_DEVCTL2_LTR_EN) evaluates to 0. However, with Patch 12/12, it is possible that val is set to ~0 on failure. This would introduce a bug because (x & x) == (~0 & x). Since ~0 is an invalid value here, Add an extra check for ~0 to the if condition to ensure success. Suggested-by: Bjorn Helgaas Signed-off-by: Saheed O. Bolarinwa --- drivers/misc/cardreader/rts5227.c | 2 +- drivers/misc/cardreader/rts5249.c | 2 +- drivers/misc/cardreader/rts5260.c | 2 +- drivers/misc/cardreader/rts5261.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/misc/cardreader/rts5227.c b/drivers/misc/cardreader/rts5227.c index 3a9467aaa435..cab816639df1 100644 --- a/drivers/misc/cardreader/rts5227.c +++ b/drivers/misc/cardreader/rts5227.c @@ -106,7 +106,7 @@ static int rts5227_extra_init_hw(struct rtsx_pcr *pcr) rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, OLT_LED_CTL, 0x0F, 0x02); /* Configure LTR */ pcie_capability_read_word(pcr->pci, PCI_EXP_DEVCTL2, &cap); - if (cap & PCI_EXP_DEVCTL2_LTR_EN) + if ((cap != (u16)~0) && (cap & PCI_EXP_DEVCTL2_LTR_EN)) rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, LTR_CTL, 0xFF, 0xA3); /* Configure OBFF */ rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, OBFF_CFG, 0x03, 0x03); diff --git a/drivers/misc/cardreader/rts5249.c b/drivers/misc/cardreader/rts5249.c index 6c6c9e95a29f..4382ac753fda 100644 --- a/drivers/misc/cardreader/rts5249.c +++ b/drivers/misc/cardreader/rts5249.c @@ -119,7 +119,7 @@ static void rts5249_init_from_cfg(struct rtsx_pcr *pcr) u16 val; pcie_capability_read_word(pcr->pci, PCI_EXP_DEVCTL2, &val); - if (val & PCI_EXP_DEVCTL2_LTR_EN) { + if ((val != (u16)~0) && (val & PCI_EXP_DEVCTL2_LTR_EN)) { option->ltr_enabled = true; option->ltr_active = true; rtsx_set_ltr_latency(pcr, option->ltr_active_latency); diff --git a/drivers/misc/cardreader/rts5260.c b/drivers/misc/cardreader/rts5260.c index 7a9dbb778e84..3d52c86aaaa3 100644 --- a/drivers/misc/cardreader/rts5260.c +++ b/drivers/misc/cardreader/rts5260.c @@ -519,7 +519,7 @@ static void rts5260_init_from_cfg(struct rtsx_pcr *pcr) u16 val; pcie_capability_read_word(pcr->pci, PCI_EXP_DEVCTL2, &val); - if (val & PCI_EXP_DEVCTL2_LTR_EN) { + if ((val != (u16)~0) && (val & PCI_EXP_DEVCTL2_LTR_EN)) { option->ltr_enabled = true; option->ltr_active = true; rtsx_set_ltr_latency(pcr, option->ltr_active_latency); diff --git a/drivers/misc/cardreader/rts5261.c b/drivers/misc/cardreader/rts5261.c index 195822ec858e..7e1188740194 100644 --- a/drivers/misc/cardreader/rts5261.c +++ b/drivers/misc/cardreader/rts5261.c @@ -440,7 +440,7 @@ static void rts5261_init_from_cfg(struct rtsx_pcr *pcr) u16 val; pcie_capability_read_word(pcr->pci, PCI_EXP_DEVCTL2, &val); - if (val & PCI_EXP_DEVCTL2_LTR_EN) { + if ((val != (u16)~0) && (val & PCI_EXP_DEVCTL2_LTR_EN)) { option->ltr_enabled = true; option->ltr_active = true; rtsx_set_ltr_latency(pcr, option->ltr_active_latency); From patchwork Fri Jul 31 11:02:31 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: 11694747 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 B195B138C for ; Fri, 31 Jul 2020 12:02:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9978622CA1 for ; Fri, 31 Jul 2020 12:02:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M6Y0jv5k" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733012AbgGaMCX (ORCPT ); Fri, 31 Jul 2020 08:02:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732699AbgGaMCW (ORCPT ); Fri, 31 Jul 2020 08:02:22 -0400 Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 652AAC061574; Fri, 31 Jul 2020 05:02:22 -0700 (PDT) Received: by mail-ej1-x644.google.com with SMTP id qc22so16378770ejb.4; Fri, 31 Jul 2020 05:02:22 -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=0s8kQrogwdlSPLZApHKOPIg76Pp1CNTA9YznKKgGPck=; b=M6Y0jv5kDqUnaX/yd/T2xgMQt71taFc83qH0hNkDJSCO82eBpAd0hnmaZzXzH8JwwR QxnHOUFXM4WOTonZWpymDce5CueUtu5cPdmXzfF3QkrFwjTonyaSBB6/OFutNKWXXJl7 1jUDYkKMxsmMDhL2Zw4OcJ1xStjLUKRpOJXm5Y9RjchXLuWxHlaZ4NjkFERXie4cqi+O OqAUwBdHmMok6y4FmBJihc5eH+MTABnbOjG2wVrZs5mQO/rZvl7GoIwILp5r9rZkXKaj I1ZZYBXCyxy0zsS5imx/7/w6t7tKz/PDc+l5Py3ZaKD6QtvvAyfi+GgIxAJ99ngBWThA 2OYQ== 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=0s8kQrogwdlSPLZApHKOPIg76Pp1CNTA9YznKKgGPck=; b=V7QYWryoK4+e4eZVv1xqAbRKBVzC3neKD4xzKAi7IWfFtWvTIw4riOgMzPQ/XABLDb Q44QNADShZSWV+d8eu/fS45awaQ8Zr+VLpIDFOiWb0auyWkfy3s6wVGbhM36vREVYQ/8 fNibDIYcTuKsme6vHrK8KXPxsv1t1R7oP6Hut59jdpoaTSHSNTPFmDkV+sfRC0ZhirUK wHdEUJgqIdO28U+NoPEbEkX5htcWNWV2SYpurXP61hTuSt28cPsk9TguUzJtvjpJAV10 PkEilVeEjs3JnSNTqDr4hyvbvIt8UgQY+NFqeDmLg6ZZL2h1QTSRckqqKT5zKoT4E/xw 6sBA== X-Gm-Message-State: AOAM532+tpeYjNk4BAVYrgthFq+aZXZ+S75AVLcN925cAwPwUS8f0Dwi hCeIIRqmNDgMR4zCfpeI685Vtgz8yBowbw== X-Google-Smtp-Source: ABdhPJz45zbOZzboFeAodzV6Jdd70KawW/kH4Nt1N7OyBQuz8phrmzy5Ee9QL5qqaAtYtkYbQgzHiA== X-Received: by 2002:a17:906:1c0e:: with SMTP id k14mr3597814ejg.479.1596196941171; Fri, 31 Jul 2020 05:02:21 -0700 (PDT) Received: from net.saheed (95C84E0A.dsl.pool.telekom.hu. [149.200.78.10]) by smtp.gmail.com with ESMTPSA id j5sm9091734ejk.87.2020.07.31.05.02.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 05:02:20 -0700 (PDT) From: "Saheed O. Bolarinwa" To: helgaas@kernel.org, "David S. Miller" , Kalle Valo , Jakub Kicinski Cc: "Saheed O. Bolarinwa" , bjorn@helgaas.com, skhan@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, QCA ath9k Development , linux-wireless@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v4 03/12] ath9k: Check if pcie_capability_read_*() reads ~0 Date: Fri, 31 Jul 2020 13:02:31 +0200 Message-Id: <20200731110240.98326-4-refactormyself@gmail.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20200731110240.98326-1-refactormyself@gmail.com> References: <20200731110240.98326-1-refactormyself@gmail.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On failure pcie_capability_read_dword() sets it's last parameter, val to 0. However, with Patch 12/12, it is possible that val is set to ~0 on failure. This would introduce a bug because (x & x) == (~0 & x). Since ~0 is an invalid value here, Add an extra check for ~0 to the if condition to ensure success. Suggested-by: Bjorn Helgaas Signed-off-by: Saheed O. Bolarinwa --- drivers/net/wireless/ath/ath9k/pci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath9k/pci.c b/drivers/net/wireless/ath/ath9k/pci.c index f3461b193c7a..f02b243befef 100644 --- a/drivers/net/wireless/ath/ath9k/pci.c +++ b/drivers/net/wireless/ath/ath9k/pci.c @@ -867,7 +867,8 @@ static void ath_pci_aspm_init(struct ath_common *common) 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)) { + if ((aspm != (u16)~0) && + (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 Fri Jul 31 11:02:32 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: 11694743 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 7E1B6722 for ; Fri, 31 Jul 2020 12:02:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6643A22CA1 for ; Fri, 31 Jul 2020 12:02:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QlWaplXG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732699AbgGaMC1 (ORCPT ); Fri, 31 Jul 2020 08:02:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733025AbgGaMCY (ORCPT ); Fri, 31 Jul 2020 08:02:24 -0400 Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E164DC061574; Fri, 31 Jul 2020 05:02:23 -0700 (PDT) Received: by mail-ej1-x643.google.com with SMTP id a21so31150585ejj.10; Fri, 31 Jul 2020 05:02:23 -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=eZK+H+8P4YZaGPvNdFZeiGG9Bo1EGoEt0s5F4CNNc80=; b=QlWaplXGbixFr2iaZsG5PJHSSOZbuNBUIasW8yuH1nsnVdp6YoYPMGxTOoB8aeGPjl cn2K3t/zLUCVvaaSnJcwSClDPI/NsQpHsPV9YLrXYaYwWeJ89I2ysukcyFp9knRUz/6A C1Yy8ztk7MbJ2O1f6n8/EwUzvpVmzYv3aVhmpXCFLy0CcrvflKiFRAQY1NvlEFKkwjEd 7M3+18TKCiSUH8ezZEFQRUHHM1DaiD+BvM6ftfMrAemf6hGhWP+eoJ4DEqde40kq53fv Vt/tgbEvtv1lsYX5VyhQ7PDlh++wbx6fnuf5oW+s+Z+p1JAKPLwxByyotKgX808QntiK +X2w== 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=eZK+H+8P4YZaGPvNdFZeiGG9Bo1EGoEt0s5F4CNNc80=; b=ok/E+6G8UhDrhUdh76PdpYMPzQYa4VvtED4CF3Kryw1KxNpsqysKzc//Ad0wu1PErb 3597mUZEGhg63RjOf3xkPHlesimdYIXBmFQVvAW6Qyn8yJu5YLtCPhraiGq6xg6px2yE A/Lkm52CPKcbkR3E8syuUaFcTHnj1QMM3web7pqcWj7ebJW22Qy5K1L4ru5qu9j0K263 8ZU2yfOde9OS83USExyjVKsXEM5+MQ2WT5QaQNj3dSsyXYdxnkObsL0udJmFv/dpGQ+C dZSZ5vnY4s/bcGx5ccg8t0fODK9wfzfKTeKIQ+8qaeDeSU/DYBAbyJpHCW9CQyJN6t9o FEeQ== X-Gm-Message-State: AOAM532J3Cs1HI80hWuWEAHG0AZIITGQ1H3pvunKRPhwtJ4/n0eMzT6H E4gQYGrZXgCOirX/8d0cXiI= X-Google-Smtp-Source: ABdhPJzseAgg1rg1tVy8ApT5RrpMw/6kYsnooL/dOwqEDLtZ6RfM9YbjqXKCNWBVO0h/MP8NAaoBeQ== X-Received: by 2002:a17:906:c1c3:: with SMTP id bw3mr3941716ejb.8.1596196942684; Fri, 31 Jul 2020 05:02:22 -0700 (PDT) Received: from net.saheed (95C84E0A.dsl.pool.telekom.hu. [149.200.78.10]) by smtp.gmail.com with ESMTPSA id j5sm9091734ejk.87.2020.07.31.05.02.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 05:02:22 -0700 (PDT) From: "Saheed O. Bolarinwa" To: helgaas@kernel.org, Kalle Valo , "David S. Miller" , Jakub Kicinski Cc: "Saheed O. Bolarinwa" , bjorn@helgaas.com, skhan@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Stanislaw Gruszka , linux-wireless@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v4 04/12] iwlegacy: Check if pcie_capability_read_*() reads ~0 Date: Fri, 31 Jul 2020 13:02:32 +0200 Message-Id: <20200731110240.98326-5-refactormyself@gmail.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20200731110240.98326-1-refactormyself@gmail.com> References: <20200731110240.98326-1-refactormyself@gmail.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On failure pcie_capability_read_dword() sets it's last parameter, val to 0. However, with Patch 12/12, it is possible that val is set to ~0 on failure. This would introduce a bug because (x & x) == (~0 & x). Since ~0 is an invalid value here, Add an extra check for ~0 to the if condition to ensure success. Suggested-by: Bjorn Helgaas Signed-off-by: Saheed O. Bolarinwa --- drivers/net/wireless/intel/iwlegacy/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/intel/iwlegacy/common.c b/drivers/net/wireless/intel/iwlegacy/common.c index 348c17ce72f5..659027563260 100644 --- a/drivers/net/wireless/intel/iwlegacy/common.c +++ b/drivers/net/wireless/intel/iwlegacy/common.c @@ -4287,7 +4287,7 @@ il_apm_init(struct il_priv *il) */ if (il->cfg->set_l0s) { pcie_capability_read_word(il->pci_dev, PCI_EXP_LNKCTL, &lctl); - if (lctl & PCI_EXP_LNKCTL_ASPM_L1) { + if ((lctl != (u16)~0) && (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 Fri Jul 31 11:02:33 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: 11694725 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 A724D138C for ; Fri, 31 Jul 2020 12:02:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F33422CB2 for ; Fri, 31 Jul 2020 12:02:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="q1ELpRRF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733034AbgGaMC1 (ORCPT ); Fri, 31 Jul 2020 08:02:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733029AbgGaMCZ (ORCPT ); Fri, 31 Jul 2020 08:02:25 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60CA1C061575; Fri, 31 Jul 2020 05:02:25 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id g19so17353807ejc.9; Fri, 31 Jul 2020 05:02:25 -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=+B0ZiRGGkQHGfacBVvFgt+7CbN36ujRN2OQHpeuEl8Q=; b=q1ELpRRFFJl8UZ7DlKSBerPXQVxyKAd4T3Rh0sn2R47QsC0y9Bjo6tJovpznNhS8yR 1ky2nz6HbkWcz/wRA3cUSi86NBcbDAf4+sQAuPbHZ8KjHOPop1D8Cs+efmggmlP6kaTE cejWvPxN+7BdWCABfsSrVCZ4a5ZrEbPMMx43Rj6x8ChHzQReQfKVL+7BtF+0ppl8pHIg OL7ouoqnTXagdt4YbGlYplW9EAo5EKk4QJ1SbxuVOJbBf7HvSjYGpb3GROvrXv/pNevl XjTzuyStpqPFCaHph9dgTIXXlp1veqq0qMTJH3ugoZ/2xMD+1DQd5SwmH+/K6LZVIxpl iQSg== 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=+B0ZiRGGkQHGfacBVvFgt+7CbN36ujRN2OQHpeuEl8Q=; b=fzWphx4Ujf37TII2q03MipMpictfkM3Yqkwu+mu6iJqcvNtjI1hRAN1DFt0nhonxCD ueXbWJ6Zu7fpFbW6j/GR2+pIBz78VZoOLuf2qhSx4z9BClPWf5+gaJxJJ7GRNoFep8P1 W73nk9cEW10plqGsMffmWf7Njnh2yR4rGWKdtHIOQvYeg6cQTUXh/gPI4YCSoYAxkal9 NxZlmpWE026lRKd/tMXuXG+2NIJMmHzK2uUMCnYdkSN5/FoGoq+Btp6sQJF5lsUA1J3f YxYZgGyLpIkV5Lfn0JdzbG80dgeD1WroAZRdinQKX4Kv2efl6cwXQQvZNZ6ImGk5qRNc NY4g== X-Gm-Message-State: AOAM533IHQS426NleByawD7pFIc54XMruY2bLlX7YgoJTuhm0OSr3oeJ m5/iLipUg1ynm29iNl4VZjA= X-Google-Smtp-Source: ABdhPJxgR17bqYSQeGy025fhxigm0MVrq5A7QiKas69UQZRDtn4IPk1fEsdjUzNRp0lVrz4itO5j9Q== X-Received: by 2002:a17:906:3756:: with SMTP id e22mr3810103ejc.487.1596196944109; Fri, 31 Jul 2020 05:02:24 -0700 (PDT) Received: from net.saheed (95C84E0A.dsl.pool.telekom.hu. [149.200.78.10]) by smtp.gmail.com with ESMTPSA id j5sm9091734ejk.87.2020.07.31.05.02.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 05:02:23 -0700 (PDT) From: "Saheed O. Bolarinwa" To: helgaas@kernel.org Cc: "Saheed O. Bolarinwa" , bjorn@helgaas.com, skhan@linuxfoundation.org, linux-pci@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 05/12] PCI: pciehp: Set "Power On" as the default get_power_status Date: Fri, 31 Jul 2020 13:02:33 +0200 Message-Id: <20200731110240.98326-6-refactormyself@gmail.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20200731110240.98326-1-refactormyself@gmail.com> References: <20200731110240.98326-1-refactormyself@gmail.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The default case of the switch statement is redundant since PCI_EXP_SLTCTL_PCC is only a single bit. Set the default case in the switch-statement to set status to "Power On" Suggested-by: Bjorn Helgaas Signed-off-by: Saheed O. Bolarinwa --- drivers/pci/hotplug/pciehp_hpc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c index 53433b37e181..b89c9ee4a3b5 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c @@ -400,14 +400,12 @@ void pciehp_get_power_status(struct controller *ctrl, u8 *status) pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, slot_ctrl); switch (slot_ctrl & PCI_EXP_SLTCTL_PCC) { - case PCI_EXP_SLTCTL_PWR_ON: - *status = 1; /* On */ - break; case PCI_EXP_SLTCTL_PWR_OFF: *status = 0; /* Off */ break; + case PCI_EXP_SLTCTL_PWR_ON: default: - *status = 0xFF; + *status = 1; /* On */ break; } } From patchwork Fri Jul 31 11:02:34 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: 11694741 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 D7C8C14E3 for ; Fri, 31 Jul 2020 12:02:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BFB3422CA1 for ; Fri, 31 Jul 2020 12:02:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lHoHf9/m" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732825AbgGaMCk (ORCPT ); Fri, 31 Jul 2020 08:02:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733033AbgGaMC1 (ORCPT ); Fri, 31 Jul 2020 08:02:27 -0400 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B01EDC061574; Fri, 31 Jul 2020 05:02:26 -0700 (PDT) Received: by mail-ej1-x641.google.com with SMTP id qc22so16378962ejb.4; Fri, 31 Jul 2020 05:02:26 -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=MwqyF9CqW8A2iZOP3zewT7pOoo+Y4wjTCBBLr9pFHV8=; b=lHoHf9/m1kx7BZ7ww7TnAOjVdHgOjMgE7yLieOTnDqQNJxPrzZpx4X7luLE6X5qwZS MSfM/WDG7Z7cYyAiYMXIgsf1/QIs51JUxiIZRyCPeJq5PHrzXYxoL9BclsHkuD1PanUC KN2TTvAcBF4bg2m0vXqdzEoStoCvDD/GLmoS+SebIRyOdOr6Eg6ZksoFBxWVKMYxIfo+ bIEm18ANbRdC7thEM0MAPhXn+OJ1s0C2E7tVzn6L91sQsZhNgOe88CHyvFgroBFxhBlS 26c6SmuBWXqQk1wEhtz7P/KBka4UMvcRd8VoKGhOPGOWlRPPvTUpLoV1+aGynqXJqYbq 2UqQ== 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=MwqyF9CqW8A2iZOP3zewT7pOoo+Y4wjTCBBLr9pFHV8=; b=mXO4CtjnGnWpGQXJId15HUrT92EeFb1dnOsIaC3JukKdHwt5W2S0Jwrtw6DXXp3x6U +V82TksGcCo2A80liQLtqJemUb4pIt92VzG+LXNaUWWWbAfRBkmN9CuzX4PWqIGNZxBw 9Q6Rr7+3fZMmHGK+VHm5cFw/NSNkN/nPPPoRb1qyD77VM6wT3XhBsxpMq4hL681OGnSR uf7CdI+rQfV8GzDeixBG7bGaHnVDqpQQriv6Jl+DGSaZ2UXxHhmL63fNr7Jx7gzV7gsB Ph3S37GiguCbP34B2y7MpXolWvMZyyCi6GErxgLo1hjkEUGM2PukOFNzA+8isc8sU1bw EVtg== X-Gm-Message-State: AOAM530KOIruYvLsuXd2iWenaEqhmV2P+6F8yF1ppcRO8MEbti6JucQF KY+z/9LzW5vNlPbt3muSfe4= X-Google-Smtp-Source: ABdhPJxTrzSFodIyak2PVFdWY/r/1cAygHW7Lv6TgpA0BgOnyI9xtpwXpNfkEtXqEA40584a4tXzpA== X-Received: by 2002:a17:906:8748:: with SMTP id hj8mr3778605ejb.477.1596196945471; Fri, 31 Jul 2020 05:02:25 -0700 (PDT) Received: from net.saheed (95C84E0A.dsl.pool.telekom.hu. [149.200.78.10]) by smtp.gmail.com with ESMTPSA id j5sm9091734ejk.87.2020.07.31.05.02.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 05:02:24 -0700 (PDT) From: "Saheed O. Bolarinwa" To: helgaas@kernel.org Cc: "Saheed O. Bolarinwa" , bjorn@helgaas.com, skhan@linuxfoundation.org, linux-pci@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 06/12] PCI: pciehp: Check if pcie_capability_read_*() reads ~0 Date: Fri, 31 Jul 2020 13:02:34 +0200 Message-Id: <20200731110240.98326-7-refactormyself@gmail.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20200731110240.98326-1-refactormyself@gmail.com> References: <20200731110240.98326-1-refactormyself@gmail.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On failure pcie_capability_read_word() sets it's last parameter, val to 0. However, with Patch 12/12, it is possible that val is set to ~0 on failure. This introduces a bug because (x & x) == (~0 & x). Since ~0 is an invalid value here, pciehp_get_power_status(): Add an extra check for ~0 on the value read. If found, set status to 'Power On' and return. pcie_wait_for_presence(): Add an extra check for no ~0 to the exit condition of the loop Suggested-by: Bjorn Helgaas Signed-off-by: Saheed O. Bolarinwa --- drivers/pci/hotplug/pciehp_hpc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c index b89c9ee4a3b5..39305aabc3a2 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c @@ -278,7 +278,7 @@ static void pcie_wait_for_presence(struct pci_dev *pdev) do { pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status); - if (slot_status & PCI_EXP_SLTSTA_PDS) + if ((slot_status != (u16)~0) && (slot_status & PCI_EXP_SLTSTA_PDS)) return; msleep(10); timeout -= 10; @@ -399,6 +399,11 @@ void pciehp_get_power_status(struct controller *ctrl, u8 *status) ctrl_dbg(ctrl, "%s: SLOTCTRL %x value read %x\n", __func__, pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, slot_ctrl); + if (slot_ctrl == (u16)~0) { + *status = 1; /* On */ + return; + } + switch (slot_ctrl & PCI_EXP_SLTCTL_PCC) { case PCI_EXP_SLTCTL_PWR_OFF: *status = 0; /* Off */ From patchwork Fri Jul 31 11:02:35 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: 11694737 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 6E0A8138C for ; Fri, 31 Jul 2020 12:02:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5702422CA1 for ; Fri, 31 Jul 2020 12:02:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mX+NGt0G" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733051AbgGaMCb (ORCPT ); Fri, 31 Jul 2020 08:02:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733045AbgGaMC2 (ORCPT ); Fri, 31 Jul 2020 08:02:28 -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 13C15C06174A; Fri, 31 Jul 2020 05:02:28 -0700 (PDT) Received: by mail-ed1-x542.google.com with SMTP id q4so18972215edv.13; Fri, 31 Jul 2020 05:02:28 -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=iuQy8w3jTC6B7f+e5+v+su2hWV/K85XhH+2elaMKuus=; b=mX+NGt0GAao51iB7oaEfO5+Btfka8TE/iCN9cnpXnNXnPfsggcBwStFE9SJ7n5EFNY jdMFPXe/UGbl0eBCTUV/gPshZTOV/RtMC0+K0sWnHYgY8gJr334m9IIIelnNoSDq6RAm PPvOdXtA4osZ4abuOYMB1Irc9HnBU7cxU0kwk0eejbhv9hq6X3XyYT4inmGtiS53gIgR ZiZb/sRX3OSs5GpMMr80sJDOqSQ8YpXdt51eHE3GJ5JtzQOMS1cw+lx/A6r33aMSGKLo Q/lJ4lkI9ut0SlODtbMP5L4nvqXTGYkyAPQ/6BgtdlGRVhRdb2rl8Cp163guf8Cg6IdL Uw7Q== 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=iuQy8w3jTC6B7f+e5+v+su2hWV/K85XhH+2elaMKuus=; b=rZLLBlUgaa8jQyxbwhIT2jYYDu0jxAa89iNxPebzv8Jxf3Uoopms+cvUayua2VLBrE 2PoLM7FPx1u/Y+LuqkaCj7xL+kYeLulIN499lHw4z4jNDfNzh8mjVjZGTnYQ8MslPa3H HC0ksFxwobEkg5xBSugL9yFdqVIHpB2uDILoTSQRzb8NvLS9J6ANgfdna46r0rdGySXU Lqsz/sY6fI4MbGRUabW2ovzszzaqmadq2cL0AtPurmQ/eqPTjwkPp1iD3LQKSRer3smf VKZmZ6anf6+gnD7XjBFTeQI7wurd45O2JU/ghOEP8o2aGruZ2n0ckUOJ2oCy6KqqHejY 1/bA== X-Gm-Message-State: AOAM533QiQly+xk4eDI06s3OaZIqR6kz0NXaEGjVZqqDfAKLjw4V2o1n hESwG0mYYbpUrLtMZhK1tKDytSLBAICrMQ== X-Google-Smtp-Source: ABdhPJzSf08P3jMuQU718EQhoumM6CT4AGAq2dZFlEfSRpdPJLSq+0WSaj54UAXLkHWN8FeZq8vKKg== X-Received: by 2002:aa7:ce91:: with SMTP id y17mr3587091edv.105.1596196946844; Fri, 31 Jul 2020 05:02:26 -0700 (PDT) Received: from net.saheed (95C84E0A.dsl.pool.telekom.hu. [149.200.78.10]) by smtp.gmail.com with ESMTPSA id j5sm9091734ejk.87.2020.07.31.05.02.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 05:02:26 -0700 (PDT) From: "Saheed O. Bolarinwa" To: helgaas@kernel.org, "Rafael J. Wysocki" , Len Brown Cc: "Saheed O. Bolarinwa" , bjorn@helgaas.com, skhan@linuxfoundation.org, linux-pci@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org Subject: [PATCH v4 07/12] PCI/ACPI: Check if pcie_capability_read_*() reads ~0 Date: Fri, 31 Jul 2020 13:02:35 +0200 Message-Id: <20200731110240.98326-8-refactormyself@gmail.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20200731110240.98326-1-refactormyself@gmail.com> References: <20200731110240.98326-1-refactormyself@gmail.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On failure pcie_capability_read_*() sets it's last parameter, val to 0. However, with Patch 12/12, it is possible that val is set to ~0 on failure. This would introduces a bug because (x & x) == (~0 & x). Since ~0 is an invalid value in here, Add extra check for ~0 in the if condition to ensure success or failure. Suggested-by: Bjorn Helgaas Signed-off-by: Saheed O. Bolarinwa --- drivers/pci/pci-acpi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c index 7224b1e5f2a8..873b005947e4 100644 --- a/drivers/pci/pci-acpi.c +++ b/drivers/pci/pci-acpi.c @@ -253,7 +253,7 @@ static bool pcie_root_rcb_set(struct pci_dev *dev) return false; pcie_capability_read_word(rp, PCI_EXP_LNKCTL, &lnkctl); - if (lnkctl & PCI_EXP_LNKCTL_RCB) + if ((lnkctl != (u16)~0) && (lnkctl & PCI_EXP_LNKCTL_RCB)) return true; return false; @@ -797,7 +797,7 @@ bool pciehp_is_native(struct pci_dev *bridge) return false; pcie_capability_read_dword(bridge, PCI_EXP_SLTCAP, &slot_cap); - if (!(slot_cap & PCI_EXP_SLTCAP_HPC)) + if ((slot_cap == (u32)~0) || !(slot_cap & PCI_EXP_SLTCAP_HPC)) return false; if (pcie_ports_native)