From: Simon Horman <horms@kernel.org>
To: Jijie Shao <shaojijie@huawei.com>,
Jian Shen <shenjian15@huawei.com>,
Salil Mehta <salil.mehta@huawei.com>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org
Subject: Re: [PATCH RFC net] net: hibmcge: Release irq resources on error and device tear-down
Date: Thu, 5 Dec 2024 20:55:11 +0000 [thread overview]
Message-ID: <20241205205511.GF2581@kernel.org> (raw)
In-Reply-To: <20241205-hibmcge-free-irq-v1-1-f5103d8d9858@kernel.org>
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@kernel.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.
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",
--
2.45.2
next prev parent reply other threads:[~2024-12-05 20:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-05 17:05 [PATCH RFC net] net: hibmcge: Release irq resources on error and device tear-down Simon Horman
2024-12-05 20:55 ` Simon Horman [this message]
2024-12-06 2:24 ` Jijie Shao
2024-12-06 9:15 ` Simon Horman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241205205511.GF2581@kernel.org \
--to=horms@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=salil.mehta@huawei.com \
--cc=shaojijie@huawei.com \
--cc=shenjian15@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.