From patchwork Mon Jun 10 09:33:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 13691746 X-Patchwork-Delegate: kw@linux.com Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F28157440B for ; Mon, 10 Jun 2024 09:33:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718012028; cv=none; b=Mc8CcyKH2LF8RL0OtvvG3wzv5tUS9576gRQePNvl7PftkKOqLQyLRs98JH97TlmJ8IFMMIIdgHxcTOELI6ts4pyOJUf+nZ71lRIJrbJ8p8LfgY5n0Mdhi90m/wZ88Lok7cZAtx2/7yrnZU7w5nR8lnWEkYORJYuasQwA6Z+/O5Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718012028; c=relaxed/simple; bh=tLOcVSiD6Eqw6Yy+f53eqMdy4+lsxuB3aeWvrhbUWPM=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=sjVrSKS0YlSPMAzPAL2YGrgk1auSaTp26v1xH4mvIbG/EN0Bo+EiinFw1RyRdVxs0s8Ih7P15qvycXisiVKrX0+vhn0imveJR/tx804fNpyRJciaobmub9TIbVzSiJP/u/ir+ZlWm6hVGn0sDEgJiYW/aKvuTX5FroYuV/ZPc1I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=DxD5TyLn; arc=none smtp.client-ip=209.85.167.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="DxD5TyLn" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-5295eb47b48so4857121e87.1 for ; Mon, 10 Jun 2024 02:33:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718012023; x=1718616823; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=pzVEamgsK8pIhsebOuX84FJsT0b+I1ivveKg0N5OLWc=; b=DxD5TyLnUt2vJ5eV6h8gmlNIM5sfKsNMxoZxcrFkXMM+IfaORIQCFuAgNCq9/XIsIX /lUn2W+QfQddSG7CeKqJiKdp0uKZm7Hs/Ym7AyuKC6glA4riQ86KUA3AKP35NGCrRWW9 y+Oi1CbUGU+J/iHI7iVQ3PnwvRRjFVbKPWaER32KwxfApqigTaFEOIXWim1/URWk/SJR thiE6UObycwYrvGtt5gYlOUgVDlnP89S7+88D81FJ1Q/ty+dpfXui8OPK1IkBJpJwMn/ 8hb6ap0Nq8wFKgEGZwC3BZbwPKvinfDSyCpWFw0e6Qj9+xWJk5DnAA1tc9FnzhCsyGL6 3yLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718012023; x=1718616823; h=in-reply-to:content-disposition:mime-version:message-id:subject:cc :to:from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pzVEamgsK8pIhsebOuX84FJsT0b+I1ivveKg0N5OLWc=; b=AdleGni08o4v8Snl5ROB/gf+ttVohSx4aTm33oc+/nSsR8t2UUnhWQOudr6WTNbfA3 Lsccl5ACvm7fRRPpvl+Nvu9LnZrdn8wCu9q3Prvo2leA/UCt4QRys68BamEBNN2kHUMT NRFSypThEiHtlcCcO07gjkbgbkQ90L3504DTBL8Ai9ZVRSfjiiljEGESSkVt2nQgc9Yh AkgDpS4mLkZxyUmXOAERE3hTkTLXaWWxcSyifmGLNy8PJqNX7io/8BxnKKpofabofDiV rWj6dKb5pp5xjQx6oZdUlAVcaZykI+9f2T5uov1Ayk2tZwyh2L1TE+hnO4JJ4BOIT70Z lSNQ== X-Forwarded-Encrypted: i=1; AJvYcCWD0EeLgb8knPtZswI3+IKC8jST64z0qYBqJtuKUOu+lVXMDCKNHEWcYiBOKLUR/VYX9OD15HRRZOsyvtnv7Zh5Ty06DGI4Ek1O X-Gm-Message-State: AOJu0YzAH57xh/Cl1Msf5foxBE1GdZbvk4EmmsnZZYXaLIf+7aCWgQxu 8ArNwC74ft9o0kkhc0e/xyp4GOZcurHSdb7Cz5KSBDmfQjfenx8dn+nG0RXnAE0= X-Google-Smtp-Source: AGHT+IEjZLgV6Wy1oAxIIdW1ddfOocWe7sK0ReqlNbZA+bPWxFoLzpJukeMXV37eZ5OiEJagfcMF0A== X-Received: by 2002:a05:6512:61b:b0:52c:7fc3:601 with SMTP id 2adb3069b0e04-52c7fc306f4mr2851793e87.61.1718012023012; Mon, 10 Jun 2024 02:33:43 -0700 (PDT) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35f0d512556sm7087985f8f.29.2024.06.10.02.33.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 02:33:42 -0700 (PDT) Date: Mon, 10 Jun 2024 12:33:39 +0300 From: Dan Carpenter To: Frank Li Cc: Jon Mason , Dave Jiang , Allen Hubbe , Manivannan Sadhasivam , Krzysztof =?utf-8?q?Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , ntb@lists.linux.dev, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH 1/2] PCI: endpoint: Clean up error handling in vpci_scan_bus() Message-ID: <68e0f6a4-fd57-45d0-945b-0876f2c8cb86@moroto.mountain> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <6eacdf8e-bb07-4e01-8726-c53a9a508945@moroto.mountain> X-Mailer: git-send-email haha only kidding Smatch complains about inconsistent NULL checking in vpci_scan_bus(): drivers/pci/endpoint/functions/pci-epf-vntb.c:1024 vpci_scan_bus() error: we previously assumed 'vpci_bus' could be null (see line 1021) Instead of printing an error message and then crashing we should return an error code and clean up. Also the NULL check is reversed so it prints an error for success instead of failure. Fixes: e35f56bb0330 ("PCI: endpoint: Support NTB transfer between RC and EP") Signed-off-by: Dan Carpenter Reviewed-by: Ilpo Järvinen --- drivers/pci/endpoint/functions/pci-epf-vntb.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c index 8e779eecd62d..7f05a44e9a9f 100644 --- a/drivers/pci/endpoint/functions/pci-epf-vntb.c +++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c @@ -1018,8 +1018,10 @@ static int vpci_scan_bus(void *sysdata) struct epf_ntb *ndev = sysdata; vpci_bus = pci_scan_bus(ndev->vbus_number, &vpci_ops, sysdata); - if (vpci_bus) - pr_err("create pci bus\n"); + if (!vpci_bus) { + pr_err("create pci bus failed\n"); + return -EINVAL; + } pci_bus_add_devices(vpci_bus); @@ -1338,10 +1340,14 @@ static int epf_ntb_bind(struct pci_epf *epf) goto err_bar_alloc; } - vpci_scan_bus(ntb); + ret = vpci_scan_bus(ntb); + if (ret) + goto err_unregister; return 0; +err_unregister: + pci_unregister_driver(&vntb_pci_driver); err_bar_alloc: epf_ntb_config_spad_bar_free(ntb); From patchwork Mon Jun 10 09:33:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 13691747 X-Patchwork-Delegate: kw@linux.com Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 972497441A for ; Mon, 10 Jun 2024 09:33:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718012037; cv=none; b=aA6MoRZYKR2feb3iA4XddO3b/TR5oVA7xyJf3noUxpCKP4ZjrqC46ocFtYanLJ/rfYwOhWUMAcKJV0kjuAsQof9RuJ7B6VkwXQpPHthzeL/hD56utF9hjLpEWL7qXHy4fmjlpWt6wPxHDJPxxIKUHYVkhAgnsjFc9RVlxDIKPNw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718012037; c=relaxed/simple; bh=Y4u8UCZ3N7F3nxprunHyg90+5gvVlDurQflxxTdao7w=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=RV0rfDFFqXRwF0pgRrSy4dzp7MBO41Q8BDcgCasTD5jotSKT/yDrXsw1/Q4/5W3RyO40KyrFQAvtVQAnXm3Z2E/9QNW235pgFn4xhROSm9Hj5YEXY83Tplxhsvy21OtPfJG8++0FxcB8oWAv9to9fxL23qEHchPcP68w4Zc4ka4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Ax/Mf6sL; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Ax/Mf6sL" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-42189d3c7efso8467125e9.2 for ; Mon, 10 Jun 2024 02:33:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718012034; x=1718616834; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=JfyZWlscKr9Yqn9KGPRWZidB/h/j24q5WeuU1z+bRpQ=; b=Ax/Mf6sLHu5jOpJbfna2GjAKKyTeZlVxGKt9vqDmcPFxgHzmMdUGuRTeOn83du+Jrn NAwsgmrhIjc70Fj1RoJuX9gvm2E3bGDsniWdFEa5ysGYETq7gvLwQ65pT2A+3BOyol3z dB4G+R8TSoBEFeO7AQvoOtGRWHryUBFEKOhDXwy82D/Jo/PyQb34soDNfEe5enHOki3A v0rnokt/IqPZEbaASx9rShbaLZZkLXew5yi12On6MZ9+kocUk2Z4pa9ew48212Ikkl7c EsB8CKDT8aUwcAcevdMJmnu0ed9rlj/idmM3vRse096a538WU4bmfXL0+w1BSWFnG6UQ RFrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718012034; x=1718616834; h=in-reply-to:content-disposition:mime-version:message-id:subject:cc :to:from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JfyZWlscKr9Yqn9KGPRWZidB/h/j24q5WeuU1z+bRpQ=; b=oSQFOpcElgru4mY8LMg9h2DmBu5YO5NVLWi2U+97Ie0AcjW2/AePFUsWXC8KnOnLnB cz/YnxTqz6mO19YGu74OCONQgkxzDwLxL2aXzDPrGWBe5cmeqR0a7ra01Y/3AODzU/Ta n6lXhsHLzRKo4MG721Agua+r0sk/QYvPqodBe2kCzHOKJykaeIHnRNSBDKWlo3lGchU1 WOzSDshX/3XBcXXm0pnHSQEQhOoiW1nMweHH+XDhSQ91Z7GknbsZNI/8imfRpE9adKgs nujqztYsXyiu0C9q4WtTDa44AFUfg17Yac+k6JIsCIj8+OLhsfZoGB0k8apWBeHmqcNL ABDA== X-Forwarded-Encrypted: i=1; AJvYcCVO5q/S77cCZ9dX2zQxn32Od+vcsXiin8JzZjTgBHLi4u6yyvvOWVrigmYFWEpXVV/BbPr+sbm5XG2SFAqURZJeZ771XOWWy2oW X-Gm-Message-State: AOJu0YylhhyOQ08BhhNqsCIDMQgSvHaswuFw5Xijxt2Psizfncj+wmD9 3oEUZ6OX4X256czkSFlsiyC+N9BOMRQNDvzgYGU17yKqigwU36OJm7ZeoXPkki0= X-Google-Smtp-Source: AGHT+IHV0SNoUbda6LDPv2KbyHC0xdaTqp83BCe78LwJZFcnLMqusq8VSWFXidvAy3Xd8mcDYj3/2w== X-Received: by 2002:a05:600c:4748:b0:421:edf4:1e89 with SMTP id 5b1f17b1804b1-421edf42181mr16200015e9.4.1718012033827; Mon, 10 Jun 2024 02:33:53 -0700 (PDT) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4215c2c7e8fsm136565045e9.38.2024.06.10.02.33.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 02:33:53 -0700 (PDT) Date: Mon, 10 Jun 2024 12:33:49 +0300 From: Dan Carpenter To: Frank Li Cc: Jon Mason , Dave Jiang , Allen Hubbe , Manivannan Sadhasivam , Krzysztof =?utf-8?q?Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , ntb@lists.linux.dev, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH 2/2] PCI: endpoint: Fix epf_ntb_epc_cleanup() a bit Message-ID: Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <6eacdf8e-bb07-4e01-8726-c53a9a508945@moroto.mountain> X-Mailer: git-send-email haha only kidding There are two issues related to epf_ntb_epc_cleanup(). 1) It should call epf_ntb_config_sspad_bar_clear(). 2) The epf_ntb_bind() function should call epf_ntb_epc_cleanup() to cleanup. I also changed the ordering a bit. Unwinding should be done in the mirror order from how they are allocated. Fixes: e35f56bb0330 ("PCI: endpoint: Support NTB transfer between RC and EP") Signed-off-by: Dan Carpenter Reviewed-by: Ilpo Järvinen --- drivers/pci/endpoint/functions/pci-epf-vntb.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c index 7f05a44e9a9f..874cb097b093 100644 --- a/drivers/pci/endpoint/functions/pci-epf-vntb.c +++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c @@ -799,8 +799,9 @@ static int epf_ntb_epc_init(struct epf_ntb *ntb) */ static void epf_ntb_epc_cleanup(struct epf_ntb *ntb) { - epf_ntb_db_bar_clear(ntb); epf_ntb_mw_bar_clear(ntb, ntb->num_mws); + epf_ntb_db_bar_clear(ntb); + epf_ntb_config_sspad_bar_clear(ntb); } #define EPF_NTB_R(_name) \ @@ -1337,7 +1338,7 @@ static int epf_ntb_bind(struct pci_epf *epf) ret = pci_register_driver(&vntb_pci_driver); if (ret) { dev_err(dev, "failure register vntb pci driver\n"); - goto err_bar_alloc; + goto err_epc_cleanup; } ret = vpci_scan_bus(ntb); @@ -1348,6 +1349,8 @@ static int epf_ntb_bind(struct pci_epf *epf) err_unregister: pci_unregister_driver(&vntb_pci_driver); +err_epc_cleanup: + epf_ntb_epc_cleanup(ntb); err_bar_alloc: epf_ntb_config_spad_bar_free(ntb);