* Re: [PATCH] net: liquidio: fix BAR resource leak on PF number failure
2026-06-20 8:37 [PATCH] net: liquidio: fix BAR resource leak on PF number failure Haoxiang Li
@ 2026-06-22 13:48 ` Simon Horman
0 siblings, 0 replies; 2+ messages in thread
From: Simon Horman @ 2026-06-22 13:48 UTC (permalink / raw)
To: Haoxiang Li
Cc: andrew+netdev, davem, kuba, pabeni, felix.manlunas,
ricardo.farrington, netdev, linux-kernel, stable
On Sat, Jun 20, 2026 at 04:37:28PM +0800, Haoxiang Li wrote:
> If cn23xx_get_pf_num() fails, the function returns without
> unmapping either BAR. Unmap both BARs before returning from
> the error path.
I think it would be worth noting how this problem was found,
and if a publicly available tool was used, naming it.
>
> Fixes: 0c45d7fe12c7 ("liquidio: fix use of pf in pass-through mode in a virtual machine")
> Cc: stable@vger.kernel.org
> Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
There is an AI-generated review of this patch available on sashiko.dev.
I don't think the issue raised there directly affects this patch.
But you may want to consider looking into that in the context of
a separate follow-up.
> ---
> drivers/net/ethernet/cavium/liquidio/cn23xx_pf_device.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/cavium/liquidio/cn23xx_pf_device.c b/drivers/net/ethernet/cavium/liquidio/cn23xx_pf_device.c
> index 75f22f74774c..a1548ca81ecd 100644
> --- a/drivers/net/ethernet/cavium/liquidio/cn23xx_pf_device.c
> +++ b/drivers/net/ethernet/cavium/liquidio/cn23xx_pf_device.c
> @@ -1167,8 +1167,11 @@ int setup_cn23xx_octeon_pf_device(struct octeon_device *oct)
> return 1;
> }
>
> - if (cn23xx_get_pf_num(oct) != 0)
> + if (cn23xx_get_pf_num(oct) != 0) {
> + octeon_unmap_pci_barx(oct, 0);
> + octeon_unmap_pci_barx(oct, 1);
> return 1;
> + }
>
> if (cn23xx_sriov_config(oct)) {
> octeon_unmap_pci_barx(oct, 0);
I think this would be best handled by introducing an idiomatic goto unwind
ladder to this function. Something like this (compile tested only!):
diff --git a/drivers/net/ethernet/cavium/liquidio/cn23xx_pf_device.c b/drivers/net/ethernet/cavium/liquidio/cn23xx_pf_device.c
index 75f22f74774c..73362b92d0fd 100644
--- a/drivers/net/ethernet/cavium/liquidio/cn23xx_pf_device.c
+++ b/drivers/net/ethernet/cavium/liquidio/cn23xx_pf_device.c
@@ -1163,18 +1163,14 @@ int setup_cn23xx_octeon_pf_device(struct octeon_device *oct)
if (octeon_map_pci_barx(oct, 1, MAX_BAR1_IOREMAP_SIZE)) {
dev_err(&oct->pci_dev->dev, "%s CN23XX BAR1 map failed\n",
__func__);
- octeon_unmap_pci_barx(oct, 0);
- return 1;
+ goto err_free_barx_0;
}
if (cn23xx_get_pf_num(oct) != 0)
- return 1;
+ goto err_free_barx_1;
- if (cn23xx_sriov_config(oct)) {
- octeon_unmap_pci_barx(oct, 0);
- octeon_unmap_pci_barx(oct, 1);
- return 1;
- }
+ if (cn23xx_sriov_config(oct))
+ goto err_free_barx_1;
octeon_write_csr64(oct, CN23XX_SLI_MAC_CREDIT_CNT, 0x3F802080802080ULL);
@@ -1205,6 +1201,12 @@ int setup_cn23xx_octeon_pf_device(struct octeon_device *oct)
oct->coproc_clock_rate = 1000000ULL * cn23xx_coprocessor_clock(oct);
return 0;
+
+err_free_barx_0:
+ octeon_unmap_pci_barx(oct, 0);
+err_free_barx_1:
+ octeon_unmap_pci_barx(oct, 1);
+ return 1;
}
EXPORT_SYMBOL_GPL(setup_cn23xx_octeon_pf_device);
--
pw-bot: changes-requested
^ permalink raw reply related [flat|nested] 2+ messages in thread