Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp2598167ybg; Fri, 31 Jul 2020 05:03:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrTFAoHoYymgP0WJqpLGvsLEnmSGjpI3OrKQ0dMmsX5c/PPVHhKeLJ53BiTTGwkwXRpaRr X-Received: by 2002:a05:6402:1b1c:: with SMTP id by28mr3624074edb.89.1596197013624; Fri, 31 Jul 2020 05:03:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596197013; cv=none; d=google.com; s=arc-20160816; b=iUy6sHZ/3FaJMC4MutzKtcVUVRU+8eHZufsueSg7+hGqxJ7oDOwSUEwUp7AP8hMO0x ml5p9nAcHBLYq4fe+siXbVqaRj3RB5UM8k7KxJPsHc+K+U6Y9iZjz6BHtAdU9doOVXPT YOHQMaUhJ1Cbuv0wc8LBCP+MTH8v2z3zRS8Y5UNj2R7hhYYlnrg/B5kgLUROQ+x8M4be l9kRsUOL1Eigjf0kJxBM9BjDZR+HO8Z3gwDzddd0ZYZIkpC0Bz6ds6vh4mpvUVXSPeO1 JjUjaZYrZfoAZzAnqW7HArwxafhinh59FwP+zfn3PjiHZLQyDA4nPMR/S7A0DEy+Zavl iLAQ== 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=MwqyF9CqW8A2iZOP3zewT7pOoo+Y4wjTCBBLr9pFHV8=; b=ApzJFoqW402HD7t8zIGiPy/G6eKiagcOhxddyt5S9JmEkTbegT0V3t6t+UoJy+R/B4 ILi+7Z7jysg8rvQcVUe9m4O5wvwj7xPHCp18CdfhTFlmlbMM/Gv5AR4gtEsUfNm3dsUL cHZ8oCEhjaFoaC3YFa0nljpM7P71xCVCBdPpAjtC67BAfO0Z+j2c5MYbsB14juzWx1qB bKrj0SbH5JvmP96BGCrZYN5Ux9j/wjJYhxa9/Zne/4mPuA2WSPdwW2qb1cI0u9izAHwZ yePQ7v/KPoRVikMIZ4UT4NxN9RoWZcxezszRHdC30gvN62rilTbky5diqCa491g3P6vS POCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="lHoHf9/m"; 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 h27si624770edj.279.2020.07.31.05.03.10; Fri, 31 Jul 2020 05:03:33 -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="lHoHf9/m"; 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 S1733045AbgGaMCl (ORCPT + 99 others); Fri, 31 Jul 2020 08:02:41 -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-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 */ -- 2.18.4