Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp40593ybt; Mon, 6 Jul 2020 03:35:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0X/F/rn31wpL1y+/xT23TfiyUmTrA/oerLDSvdwm3e4ZFB0y4Tv8Ajr1KjAz3Na+l0Mrt X-Received: by 2002:a05:6402:ca3:: with SMTP id cn3mr57025624edb.64.1594031744574; Mon, 06 Jul 2020 03:35:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594031744; cv=none; d=google.com; s=arc-20160816; b=wHU9X06XPb5eqWR31iP/LyQMrfol3oVsg2gCkHFmUoy0HD2YT9IvI7Mze9SuWOFZ/a +WzeKU9pYVEgdavYwPM1B9/c/9cMPJg0ICWWpDHRe9/qBFl8bTuZROZxnsMGpkSAJrmf xl7IzQgTsI3+vUTxst4OLZZD7dJ3R1aGSFt+MOeD4oGWPtPwNCYztKQUnaDMvMbFpDk1 OdwhnTuR8vN1vhswZjAtd5ErCBKXqVk8aJ18IqgLlMHwCleMnfdf9PJkaDPJwQKwvj+A mElJZROJAaIs8m6odfHxlKHvHSroEBTJnXfszidyHIvBrIbQLC1FU0fyiUXywyl64BCr OIZg== 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=zIc+ryXbVspn9u+GSLsSwM5Cff3RjamOLjlQZyxFr+U=; b=ywL9Avsc974a9ORz3qvcShmuzFWA/rIVhgA1dwnzcUb/moN2OoZDVNCv6oBuH1R+bt h/4DnbZS7FumixoeuBrT6+Q6DNSM4ExnxcnNrjxlF5KTyLEXoiEzKstiRVit72suh8+4 tZjmMLAHTG4LekC7dIAke/ca+EkLt8PJDzi6U00PPgTCpu4ohdCFoKqHSAgqkrymIxk7 7mF8ImCl9KSU6zd50IJpIDsQkovtkvOeqM+Yjv+3Kwim9UpRt+IXSHlpp7Dbdnyju5m/ CYZZAN7EqML/WmUF80BJEagCnIzTtxSHpugGuduj30KOcxWtlRzfqSvvYRkzBRnGPT4m BcLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cg2exXge; 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 cy5si12881499edb.554.2020.07.06.03.35.21; Mon, 06 Jul 2020 03:35:44 -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=cg2exXge; 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 S1728930AbgGFKb4 (ORCPT + 99 others); Mon, 6 Jul 2020 06:31:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728733AbgGFKbz (ORCPT ); Mon, 6 Jul 2020 06:31:55 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3E4EC061794; Mon, 6 Jul 2020 03:31:54 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id f18so32169051wrs.0; Mon, 06 Jul 2020 03:31: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=zIc+ryXbVspn9u+GSLsSwM5Cff3RjamOLjlQZyxFr+U=; b=cg2exXge4dbjo5XG0pFDqzL4EhbxVye2Y2SrCQv/P2Dg2tU+/5QN+wUT5XfILrK669 StfO6eeTUTyg3zJq2I3CJ+rZAEjFi03MOLGodp2ZjGdKraqFoyDCCQLbp+stXcS0rSGk EeJxe8rvAE8Tbp6sce9+rVFKzDBtgvB3d6wCyI5HatgTE2+x3QE6ooHDcRIP0cPGFQp7 z1A+03J1XT8xTyK3YOYa4o61qT3mqZBb5lSTgp0LNkck2wLm8qRcpiFspO81+BGlBc4Z yus+TgOMZRecaarzNx1To3/r7LBqROPWCwgsUF0Y4B8XTureThhh1unrmpXQuys2tGqC ihZA== 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=zIc+ryXbVspn9u+GSLsSwM5Cff3RjamOLjlQZyxFr+U=; b=fDYAUgQ6ARu476ErYISfWRE9bO5Ctz1A7qS9/2wDUmgJrSCW6T+qsDzjrbVd1hQcwj g1bUFUX8EXnK3FDb1VE3iupTGrD2VKI9tm6Vc3fT80aTZfRaMGr5zJx0Tgb5g7xKKJui El4OO7TU3w1Cuen37zosDyLLRqM/VyUu4R/g9yLy8npTKpIC5EoNESq6F6ueCjIj/Aco ky+UQ5DCUHoaQhfvHRaIaR2TUXTB0fSmnAE7k9aw1e1tk75SZQYrWgXje+CMgMkoetrG Dmk67fmyFjnLwuY2E8DCHf/3TpzU+7Cab8d74+27WlAJ/8n0bZMQuPCI3tU58+oQcND1 HZRg== X-Gm-Message-State: AOAM531UeooH/NVi1BJ5WMtaiW7uN8XfreXJ0xqsrfmZ+t/MHXSG2m9v A2j0wReKdOeZw5oCnZo8bY+sbt1eGybM4Q== X-Received: by 2002:adf:91e1:: with SMTP id 88mr41365811wri.89.1594031513765; Mon, 06 Jul 2020 03:31:53 -0700 (PDT) Received: from net.saheed (51B7C2DF.dsl.pool.telekom.hu. [81.183.194.223]) by smtp.gmail.com with ESMTPSA id 22sm24216859wmb.11.2020.07.06.03.31.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2020 03:31:53 -0700 (PDT) From: Saheed Olayemi Bolarinwa To: helgaas@kernel.org Cc: Bolarinwa Olayemi Saheed , bjorn@helgaas.com, Lukas Wunner , skhan@linuxfoundation.org, linux-pci@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/11 RFC] PCI: pciehp: Validate with the return value of pcie_capability_read_*() Date: Mon, 6 Jul 2020 11:31:13 +0200 Message-Id: <20200706093121.9731-4-refactormyself@gmail.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <20200706093121.9731-1-refactormyself@gmail.com> References: <20200706093121.9731-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 any failure pcie_capability_read_word() sets it's last parameter, *val to 0. If pci_config_read_word() fails the *val is reset to 0. Any function which check only for a frabricated ~0 which fail in this case. Include a check on the return value of pcie_capability_read_dword() to confirm success or failure. Suggested-by: Bjorn Helgaas Signed-off-by: Bolarinwa Olayemi Saheed --- drivers/pci/hotplug/pciehp_hpc.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c index 53433b37e181..5af281d97d4f 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c @@ -86,10 +86,11 @@ static int pcie_poll_cmd(struct controller *ctrl, int timeout) { struct pci_dev *pdev = ctrl_dev(ctrl); u16 slot_status; + int ret; do { - pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status); - if (slot_status == (u16) ~0) { + ret = pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status); + if (ret || (slot_status == (u16) ~0)) { ctrl_info(ctrl, "%s: no response from device\n", __func__); return 0; @@ -156,6 +157,7 @@ static void pcie_do_write_cmd(struct controller *ctrl, u16 cmd, { struct pci_dev *pdev = ctrl_dev(ctrl); u16 slot_ctrl_orig, slot_ctrl; + int ret; mutex_lock(&ctrl->ctrl_lock); @@ -164,8 +166,8 @@ static void pcie_do_write_cmd(struct controller *ctrl, u16 cmd, */ pcie_wait_cmd(ctrl); - pcie_capability_read_word(pdev, PCI_EXP_SLTCTL, &slot_ctrl); - if (slot_ctrl == (u16) ~0) { + ret = pcie_capability_read_word(pdev, PCI_EXP_SLTCTL, &slot_ctrl); + if (ret || (slot_ctrl == (u16) ~0)) { ctrl_info(ctrl, "%s: no response from device\n", __func__); goto out; } @@ -430,7 +432,7 @@ void pciehp_get_latch_status(struct controller *ctrl, u8 *status) * removed immediately after the check so the caller may need to take * this into account. * - * It the hotplug controller itself is not available anymore returns + * If the hotplug controller itself is not available anymore returns * %-ENODEV. */ int pciehp_card_present(struct controller *ctrl) @@ -591,8 +593,8 @@ static irqreturn_t pciehp_isr(int irq, void *dev_id) } read_status: - pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &status); - if (status == (u16) ~0) { + ret = pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &status); + if (ret || (status == (u16) ~0)) { ctrl_info(ctrl, "%s: no response from device\n", __func__); if (parent) pm_runtime_put(parent); -- 2.18.2