Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1123773ybh; Mon, 13 Jul 2020 09:56:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweY2Q3+yQ3cvng30yEA9HNYzliGmENof25rUvivskYRMYC+R96Gg0m9PZNEMAcaOcrnBeI X-Received: by 2002:a50:d501:: with SMTP id u1mr307932edi.159.1594659360588; Mon, 13 Jul 2020 09:56:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594659360; cv=none; d=google.com; s=arc-20160816; b=mJBVibDXUZAJdLeJjEya9VoRh69LueY84tXeSpqBTMFnfHpXff+7obLCUU4+MsZrYO 02p1J4fOtpdBv5F96VA6ALfEkyNgKy5a+UtjasyKfhwlHjZpivkdWnEwsLkif9mXayBO OPSkiQSUGRZ/gh+UW3T1cdte3XvJWBXgiqH1e6/h5NNkcaSoEcmhemmM5ewjNgxJIrQM /vG0VhYMJQVIsJ38oW10E0B+3doto/gtGeTIC8EWg3J5EGoQUjyo5m22TW0l3ohJYgyv 9MHbwWT7jQD9FQ+yv7UQ1R2bpcrAlD0MUgRKyUke5dBz412nWV4+K+pZ2Ycr/qj5YX6D WDsQ== 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=Vg5seoeyahxUOJ1a2of2OSXbNHc8+N6IhRiLy4XR8Ps=; b=qp+MB6NMZB4tK4tqcLI6QSU05/OYgEBvDVWjUvCMw8mWixeJLRt/9b4iOh+ggJyEgl bca+/FU496eHpGi/OUpuM1SVIjpTosYR2WxaNkjwCXgTagSeHJgNqCbZ/D3ewReY9Bw7 PO99xZOG551D/Jehv6T7VquIa8aZnv+37oBBhOflcGCle/cCtnEd3X6B+7Ui7mWoooxU YCkImuYYva5cXrAYme4naKBrjcqbqyIWDW19WQ3ffiUgE0/cl7FtLv/SC7fXItd7e807 6RKL5r/wnuiQuwqIXGIHGLvlvJJMb5tdMK4rzuN9IUm+7xyD/TaKDN3LfVzdQwjzjHAk AR+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="QThq7T/N"; 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 n20si8771854ejs.158.2020.07.13.09.55.37; Mon, 13 Jul 2020 09:56:00 -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="QThq7T/N"; 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 S1730377AbgGMQzV (ORCPT + 99 others); Mon, 13 Jul 2020 12:55:21 -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-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-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 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) -- 2.18.2