Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp794171lqb; Wed, 17 Apr 2024 10:50:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWHEXKbhbEgMV5Am36hxfcfLZAEDojsFeJWoHiydw+AsJVd1+Dc0/RK4ue13HHfHgEqotflXMl/5re+IPqdaAUoYvSt12BtEn5qo70A1w== X-Google-Smtp-Source: AGHT+IFOD/YP0AbcXoeH3JvmlqT6hunS8eO7IJ6g5aFskjvzDcYVxlzZkENz9d2eb/koGwDA7ISn X-Received: by 2002:a05:6a20:d42f:b0:1a9:f480:bd2f with SMTP id il47-20020a056a20d42f00b001a9f480bd2fmr323695pzb.55.1713376202432; Wed, 17 Apr 2024 10:50:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713376202; cv=pass; d=google.com; s=arc-20160816; b=GpoQBDoCzZIOOMU3/Yn9Yvk7IE3XAl/iVgznumHKPP7sQTP2on+BFB61bufXOe1YRL WjwwNrstUeL9on7LgeZPFQS+4piresTBy8Y/jnrAk9TLOwuUoMn27PC3HHGT0vTREbAA bZ9rlz9r63RxElzqNTCtd9SfNwSL3m3C9RzH8wK17kC1OP8b3kNFkqWCNdS7pm4SngWN wCcp2EggDZRgE9/rIbQq4GrVOlR0/yhE+KKkBqKHoGaYrel5tXyDrn7PLM45000isG3T r0DdKaXTVqTq4M7VZ4tBbvp7o3oychqNf1r/V4nso5eIisyl5NXjfNorspK9Pk8z1PKl aURQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=beq0INrLk3A0/F4l0J4JuzpENLeTpa6aKELAgDagCnI=; fh=84Lm60alC1gOD3/xwRV6wwH4oEpbIf/mN0IM+FxHkpw=; b=yw4k78e74WAmdwJnXVq+ZRn+v7QxWFUo9Ci8wmr6Ha2Stmo0ajk6nKsp+bDMeBRz1q L9R6jXOEgkPkLEQacl+SGh1r+k5Jx0k9heTJVBhYqocaqak2FfqYzmS0kSDNv5g9nYJB EuopoYmoxTYY4PEe8EYS1xcuAeQ5XyaRf4WnHseM4WlL8JYAE6XXiNwC92cfr4gZJY9+ ODFjGSXDDGbmsiEu8RMK/W9rRKHR/8hoBNZjR9B5q9tcJ39W+lTVPoOIfRrFALNvVLSl 1kicDAQ93e6LbT7gCTgeZoLSUxy3lRhId9KrDKwgc10HWj/EB/a4znjNEP6nNrYJmwLI 9ZTg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KLtzx3DR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-149010-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149010-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id b185-20020a6367c2000000b005dc9bea60fdsi11935060pgc.415.2024.04.17.10.50.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 10:50:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-149010-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KLtzx3DR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-149010-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149010-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B0DC6283FE0 for ; Wed, 17 Apr 2024 17:50:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C52CA172BCA; Wed, 17 Apr 2024 17:49:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KLtzx3DR" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0C1A171678; Wed, 17 Apr 2024 17:49:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713376191; cv=none; b=NpL9CatRJQ+iFg72MQdzV9xQtop/NCF1n0JCrtwlVQVQa7sXd6e5XYwxTsFpZnmI8ScmAw02/3LAv23vYrItB+aW5V4aDlRs62Hzavh/+NrQSTK+Kb0cUrTNO1j0zzLboFBtzG4UTW/kbBagOJd1O8xW+GuxX5tMymmAJ6QnW7Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713376191; c=relaxed/simple; bh=kKmiZAPl+q6hmp8UYUp88qDELSBUZ6KaZWZd1XSAtdk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=u6WMIROxnkbe1oYDhhb2BWqdZ8xwoIN5ebeMtC2uAsb8xSRcWDXjptHD2wMA6DtKLEaNa5RkEaXxOSxn/t8XdjQVJvTd6ElnZRSJuZAAkB8s1X4V4cO99T8uJlKZ2qUT+ZuHlwTIgVv+FGT6kqBxR0Ex/8JHzuLjdADdhWSCdNM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KLtzx3DR; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id ACCABC072AA; Wed, 17 Apr 2024 17:49:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713376190; bh=kKmiZAPl+q6hmp8UYUp88qDELSBUZ6KaZWZd1XSAtdk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KLtzx3DRHZYf8q/L8qvoWsIV1j+mXQKUIxe3GMLZ42asCImYAwJZS/fjodoBAuPdp 177Dv3Hy1M3KfWejLCuesWtBigYezXbqgMed3O0h9yaNWeoc0/yre4hzW/jF7I3R5w qCN0MUJmbhjf7O0DfU8Hx6MEfq1QzOTQWciowY1T1x6fEsfEcofdcp0sG2NX+lz4JQ VSYK6SquDVGk4ErhYIhI17i5fkVcdALqBaDquXWhcuo9FSP10dxu7Fd2D8eHu/MMrv gWR3zXZbH1NzX+Xlyhi7snGKiTBKjX0C03MIRE2JAJNBDScBAn9/JUosuRxZ4T10/D VcjsO5Xw/vqtg== Date: Wed, 17 Apr 2024 19:49:45 +0200 From: Niklas Cassel To: Manivannan Sadhasivam Cc: Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Dan Carpenter Subject: Re: [PATCH] PCI: endpoint: pci-epf-test: Make use of cached 'epc_features' in pci_epf_test_core_init() Message-ID: References: <20240417-pci-epf-test-fix-v1-1-653c911d1faa@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240417-pci-epf-test-fix-v1-1-653c911d1faa@linaro.org> On Wed, Apr 17, 2024 at 10:47:25PM +0530, Manivannan Sadhasivam wrote: > Instead of getting the epc_features from pci_epc_get_features() API, use > the cached pci_epf_test::epc_features value to avoid the NULL check. Since > the NULL check is already performed in pci_epf_test_bind(), having one more > check in pci_epf_test_core_init() is redundant and it is not possible to > hit the NULL pointer dereference. This also leads to the following smatch > warning: > > drivers/pci/endpoint/functions/pci-epf-test.c:784 pci_epf_test_core_init() > error: we previously assumed 'epc_features' could be null (see line 747) > > Reported-by: Dan Carpenter > Closes: https://lore.kernel.org/linux-pci/024b5826-7180-4076-ae08-57d2584cca3f@moroto.mountain/ > Signed-off-by: Manivannan Sadhasivam I think you forgot: Fixes: a01e7214bef9 ("PCI: endpoint: Remove "core_init_notifier" flag") > --- > drivers/pci/endpoint/functions/pci-epf-test.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c > index 977fb79c1567..0d28f413cb07 100644 > --- a/drivers/pci/endpoint/functions/pci-epf-test.c > +++ b/drivers/pci/endpoint/functions/pci-epf-test.c > @@ -743,11 +743,10 @@ static int pci_epf_test_core_init(struct pci_epf *epf) > bool msi_capable = true; > int ret; > > - epc_features = pci_epc_get_features(epc, epf->func_no, epf->vfunc_no); > - if (epc_features) { > - msix_capable = epc_features->msix_capable; > - msi_capable = epc_features->msi_capable; > - } > + epc_features = epf_test->epc_features; How about: index 977fb79c1567..4d6105c07ac0 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -735,7 +735,7 @@ static int pci_epf_test_core_init(struct pci_epf *epf) { struct pci_epf_test *epf_test = epf_get_drvdata(epf); struct pci_epf_header *header = epf->header; - const struct pci_epc_features *epc_features; + const struct pci_epc_features *epc_features = epf_test->epc_features; struct pci_epc *epc = epf->epc; struct device *dev = &epf->dev; bool linkup_notifier = false; @@ -743,12 +743,6 @@ static int pci_epf_test_core_init(struct pci_epf *epf) bool msi_capable = true; int ret; - epc_features = pci_epc_get_features(epc, epf->func_no, epf->vfunc_no); - if (epc_features) { - msix_capable = epc_features->msix_capable; - msi_capable = epc_features->msi_capable; - } - if (epf->vfunc_no <= 1) { ret = pci_epc_write_header(epc, epf->func_no, epf->vfunc_no, header); if (ret) { @@ -761,6 +755,7 @@ static int pci_epf_test_core_init(struct pci_epf *epf) if (ret) return ret; + msi_capable = epc_features->msi_capable; if (msi_capable) { ret = pci_epc_set_msi(epc, epf->func_no, epf->vfunc_no, epf->msi_interrupts); @@ -770,6 +765,7 @@ static int pci_epf_test_core_init(struct pci_epf *epf) } } + msix_capable = epc_features->msix_capable; if (msix_capable) { ret = pci_epc_set_msix(epc, epf->func_no, epf->vfunc_no, epf->msix_interrupts, @@ -814,11 +810,9 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) void *base; enum pci_barno test_reg_bar = epf_test->test_reg_bar; enum pci_barno bar; - const struct pci_epc_features *epc_features; + const struct pci_epc_features *epc_features = epf_test->epc_features; size_t test_reg_size; - epc_features = epf_test->epc_features; - test_reg_bar_size = ALIGN(sizeof(struct pci_epf_test_reg), 128); msix_capable = epc_features->msix_capable; Instead? That way, we assign msi_capable/msix_capable just before the if-statement where it is used. (Which matches how we already assign msix_capable just before the if-statement in pci_epf_test_alloc_space().) Kind regards, Niklas > + > + msix_capable = epc_features->msix_capable; > + msi_capable = epc_features->msi_capable; > > if (epf->vfunc_no <= 1) { > ret = pci_epc_write_header(epc, epf->func_no, epf->vfunc_no, header); > > --- > base-commit: 6e47dcb2ca223211c43c37497836cd9666c70674 > change-id: 20240417-pci-epf-test-fix-2209ae22be80 > > Best regards, > -- > Manivannan Sadhasivam >