[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <b9db6fe7-6d0c-4f05-96c5-242112e4fc2a@huawei.com>
Date: Fri, 6 Dec 2024 10:24:49 +0800
From: Jijie Shao <shaojijie@...wei.com>
To: Simon Horman <horms@...nel.org>, Jian Shen <shenjian15@...wei.com>, Salil
Mehta <salil.mehta@...wei.com>
CC: <shaojijie@...wei.com>, Andrew Lunn <andrew+netdev@...n.ch>, "David S.
Miller" <davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>, Jakub
Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
<netdev@...r.kernel.org>
Subject: Re: [PATCH RFC net] net: hibmcge: Release irq resources on error and
device tear-down
on 2024/12/6 4:55, Simon Horman wrote:
> On Thu, Dec 05, 2024 at 05:05:23PM +0000, Simon Horman wrote:
>> This patch addresses two problems related to leaked resources allocated
>> by hbg_irq_init().
>>
>> 1. On error release allocated resources
>> 2. Otherwise, release the allocated irq vector on device tear-down
>> by setting-up a devres to do so.
>>
>> Found by inspection.
>> Compile tested only.
>>
>> Fixes: 4d089035fa19 ("net: hibmcge: Add interrupt supported in this module")
>> Signed-off-by: Simon Horman <horms@...nel.org>
> Sorry for the noise, but on reflection I realise that the devm_free_irq()
> portion of my patch, which is most of it, is not necessary as the
> allocations are made using devm_request_irq(). And the driver seems to
> rely on failure during init resulting in device tear-down, at which point
> devres will take care of freeing the IRQs.
>
> But I don't see where the IRQ vectors are freed, either on error in
> hbg_irq_init or device tear-down. I think the following, somewhat smaller
> patch, would be sufficient to address that.
Thank you for reviewing the code.
But sorry, it's actually not needed.
I discussed this with Jakub and Jonathan:
https://lore.kernel.org/all/383f26a1-aa8f-4fd2-a00a-86abce5942ad@huawei.com/
I also add a comment in code, But I'm sorry, maybe it's a little subtle.
/* used pcim_enable_device(), so the vectors become device managed */
ret = pci_alloc_irq_vectors(priv->pdev, HBG_VECTOR_NUM, HBG_VECTOR_NUM,
PCI_IRQ_MSI | PCI_IRQ_MSIX);
Thanks,
Jijie Shao
>
> diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.c
> index 25dd25f096fe..44294453d0e4 100644
> --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.c
> +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.c
> @@ -83,6 +83,11 @@ static irqreturn_t hbg_irq_handle(int irq_num, void *p)
> static const char *irq_names_map[HBG_VECTOR_NUM] = { "tx", "rx",
> "err", "mdio" };
>
> +static void hbg_free_irq_vectors(void *data)
> +{
> + pci_free_irq_vectors(data);
> +}
> +
> int hbg_irq_init(struct hbg_priv *priv)
> {
> struct hbg_vector *vectors = &priv->vectors;
> @@ -96,6 +101,13 @@ int hbg_irq_init(struct hbg_priv *priv)
> if (ret < 0)
> return dev_err_probe(dev, ret, "failed to allocate vectors\n");
>
> + ret = devm_add_action_or_reset(dev, hbg_free_irq_vectors, priv->pdev);
> + if (ret) {
> + pci_free_irq_vectors(priv->pdev);
> + return dev_err_probe(dev, ret,
> + "failed to add devres to free vectors\n");
> + }
> +
> if (ret != HBG_VECTOR_NUM)
> return dev_err_probe(dev, -EINVAL,
> "requested %u MSI, but allocated %d MSI\n",
Powered by blists - more mailing lists