Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1137340ybh; Mon, 13 Jul 2020 10:13:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjttMLQIsfYlWjgOwgPuBpBPgJvPpl72LMbEsZzCrAY3u3UoO6zMpPhO3dWTR1h/FEm21p X-Received: by 2002:aa7:c885:: with SMTP id p5mr449182eds.100.1594660383526; Mon, 13 Jul 2020 10:13:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594660383; cv=none; d=google.com; s=arc-20160816; b=kF++6DU78/wG/41KW2n7sOrMASUg4HWxDtofLkKrorsDR2AEITzQAIef1R3X8OoNhe ZwyLie2/IS7f2v7tufJeA3GKQQsJk7nkyNsCfVnx9XvkD+cw6skLUYWa+E3P3z+nMN7D m2Xct1pw69T0mllqzIDACGppqPL2JlJJvwyNWhZM+CJEcU/BLDeztBIUmA1Z5cV0tj7x A27i5Aa62EH4AlmIeCPB1LlrGddXbwfP6JI9OwqMI80ikD4AgyvmdToznXLrjrwUFJEz 91s23ZQ/T2phEilFy0MLNxs4d2nE1JnvXFgu+wo4wWuI+axjsj0P+6CidwbtcMhUA1wy ti7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=AjfD32HKP9GelxZOkg41v9V6Gzjw1JRj8RlOK03pams=; b=gcBAu3HHQbIsrvNf3CsYTkVdDqWAE37rID7t/P9Pj32ti6KAjR0Td9UCEdjwlqBMj9 ay4Fce+TlZrN7bkXC23EbCa0Lq8gLb4i+V1gdXmdgrwctVM4rVOR7PDFdsrw/V+dVPST OeBPLhab72QG26x2KVmid2u5xlPbrKxoOocF58CeMipT8WArhkZ2KJ6sFTiyzp4Jsgoa PnZyhPIDbwmSe497WV5kSKb8ANvLAFU5lKydt8tKucr7edoEPeBmtCuhpRPvLsto+3u/ Y2PDJJnSmsTA7vcyhblDXciN00VJezohTUHTMzXdg1/EjfhKJ8SSkjcN+RQduolsyCO7 4dug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=P6ue5J2Q; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bq21si9694012ejb.301.2020.07.13.10.12.40; Mon, 13 Jul 2020 10:13:03 -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=@ziepe.ca header.s=google header.b=P6ue5J2Q; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730273AbgGMRJn (ORCPT + 99 others); Mon, 13 Jul 2020 13:09:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729659AbgGMRJn (ORCPT ); Mon, 13 Jul 2020 13:09:43 -0400 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1818C061755 for ; Mon, 13 Jul 2020 10:09:42 -0700 (PDT) Received: by mail-qk1-x742.google.com with SMTP id b4so12899090qkn.11 for ; Mon, 13 Jul 2020 10:09:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=AjfD32HKP9GelxZOkg41v9V6Gzjw1JRj8RlOK03pams=; b=P6ue5J2QVyGR013c2UC25Q9bEjmGLQLJlmEuA1j5UoaACPlwGsRU5oPQydR4VgHRAQ L1LLo1DsbWsmVVz1JJH+XrYRnbQxNVDp0Tbzha5dqUAB1U3rVrK0ZuloeI02R3+Ohmck nIhcHDRdSQZbeXNk1VGmdTIpJpVNzm4aXapDBvkADLvm+N6wGsC0Vuj5SRCjoLtTpbM6 3YNMYd60otly0jlZeIyCvHepWSBprUXUrUnc1mbSIi5+zMPYtY/xp7pglqsia5XJhfiB F8DgDcnW27IcL2XuD2u0H8FjQS8bqlDG91XFUgIbJjfpl7taOGEyt92W8DFNPIX8mT3F fvkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=AjfD32HKP9GelxZOkg41v9V6Gzjw1JRj8RlOK03pams=; b=ruAzktlnWZWXtow0fVzYDhFWevflxRqMPcaP+wcwaRXemoO/5O50XE5ZCmKrkDrTpv rbZU+osisVRXOhQEn3utr/PIQvfGCxJh2XQ83rr9sXoLmG9a5uZvVCxOOx4xTdSsvhoY sPIVQ0hUvfkBRmscz8bOQfDWyh43Q7i3hF+3nN5tUrru3hsau4fCIyuQRX5ecYmy8Jjj V2ohcICVc3xHj+5lAPdr7mVnddTHj+JFC2XBxCa4xRd9D44LG4IEpIZzcY7EGUQGcR9r ttk5SBV0WzjwQw4pvKfn9/GZJMfkgMMXwjuSXSJSOHw7gfy3Wq/JuGWYOlbt4wP8PXPB Zd4Q== X-Gm-Message-State: AOAM531mYgr4ZpxR7cd1Bd2wGfI0L2cHDaxm+ujSdjRxh2Er62clKGZQ MKagP1EJQGTGIE6lW+iZwMFt/g== X-Received: by 2002:a37:5bc4:: with SMTP id p187mr661575qkb.166.1594660182115; Mon, 13 Jul 2020 10:09:42 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-156-34-48-30.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.48.30]) by smtp.gmail.com with ESMTPSA id i35sm19119142qtd.96.2020.07.13.10.09.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2020 10:09:41 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.93) (envelope-from ) id 1jv1xV-009lWJ-4g; Mon, 13 Jul 2020 14:09:41 -0300 Date: Mon, 13 Jul 2020 14:09:41 -0300 From: Jason Gunthorpe To: "Saheed O. Bolarinwa" Cc: skhan@linuxfoundation.org, linux-rdma@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/14 v3] IB/hfi1: Check the return value of pcie_capability_read_*() Message-ID: <20200713170941.GB25301@ziepe.ca> References: <20200713175529.29715-1-refactormyself@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <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 On Mon, Jul 13, 2020 at 07:55:25PM +0200, Saheed O. Bolarinwa wrote: > From: Bolarinwa Olayemi Saheed > > 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 14/14, 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. > > This bug can be avoided if the return value of pcie_capability_read_dword > is checked to confirm success. The behaviour of the function remains > intact. > > Check the return value of pcie_capability_read_dword() to ensure success. > > Suggested-by: Bjorn Helgaas > Signed-off-by: Bolarinwa Olayemi Saheed > drivers/infiniband/hw/hfi1/aspm.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/drivers/infiniband/hw/hfi1/aspm.c b/drivers/infiniband/hw/hfi1/aspm.c > index a3c53be4072c..80d0b3edd983 100644 > +++ b/drivers/infiniband/hw/hfi1/aspm.c > @@ -24,6 +24,7 @@ static bool aspm_hw_l1_supported(struct hfi1_devdata *dd) > { > struct pci_dev *parent = dd->pcidev->bus->self; > u32 up, dn; > + int ret_up, ret_dn; > > /* > * If the driver does not have access to the upstream component, > @@ -32,14 +33,14 @@ static bool aspm_hw_l1_supported(struct hfi1_devdata *dd) > if (!parent) > return false; > > - pcie_capability_read_dword(dd->pcidev, PCI_EXP_LNKCAP, &dn); > + ret_dn = pcie_capability_read_dword(dd->pcidev, PCI_EXP_LNKCAP, &dn); > dn = ASPM_L1_SUPPORTED(dn); > > - pcie_capability_read_dword(parent, PCI_EXP_LNKCAP, &up); > + ret_up = pcie_capability_read_dword(parent, PCI_EXP_LNKCAP, &up); > up = ASPM_L1_SUPPORTED(up); > > /* ASPM works on A-step but is reported as not supported */ > - return (!!dn || is_ax(dd)) && !!up; > + return !!ret_dn && !!ret_up && (!!dn || is_ax(dd)) && !!up; > } what is all the !! for? boolean contexts already coerce to boolean Jason