From: Bastien Curutchet <bastien.curutchet@bootlin.com>
To: Maxime Chevallier <maxime.chevallier@bootlin.com>,
Woojung Huh <woojung.huh@microchip.com>,
UNGLinuxDriver@microchip.com, Andrew Lunn <andrew@lunn.ch>,
Vladimir Oltean <olteanv@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Richard Cochran <richardcochran@gmail.com>,
Arun Ramadoss <arun.ramadoss@microchip.com>
Cc: "Pascal Eberhard" <pascal.eberhard@se.com>,
"Miquèl Raynal" <miquel.raynal@bootlin.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v4 4/5] net: dsa: microchip: Free previously initialized ports on init failures
Date: Mon, 17 Nov 2025 19:51:52 +0100 [thread overview]
Message-ID: <bcd94483-281a-47e7-b82a-14064ad36129@bootlin.com> (raw)
In-Reply-To: <fed4309a-af05-4222-b9af-2ff8c655f3df@bootlin.com>
Hi Maxime,
On 11/17/25 5:28 PM, Maxime Chevallier wrote:
> Hi Bastien,
>
> On 17/11/2025 14:05, Bastien Curutchet (Schneider Electric) wrote:
>> If ksz_pirq_setup() fails after at least one successful port
>> initialization, the goto jumps directly to the global irq freeing,
>> leaking the resources of the previously initialized ports.
>>
>> Fix the goto jump to release all the potentially initialized ports.
>> Remove the no-longer used out_girq label.
>>
>> Fixes: c9cd961c0d43 ("net: dsa: microchip: lan937x: add interrupt support for port phy link")
>> Signed-off-by: Bastien Curutchet (Schneider Electric) <bastien.curutchet@bootlin.com>
>> ---
>> drivers/net/dsa/microchip/ksz_common.c | 6 ++----
>> 1 file changed, 2 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
>> index a622416d966330187ee062b2f44051ddf4ce2a78..2b6f7abea00776fafff0c1774cab297a7ef261da 100644
>> --- a/drivers/net/dsa/microchip/ksz_common.c
>> +++ b/drivers/net/dsa/microchip/ksz_common.c
>> @@ -3035,7 +3035,7 @@ static int ksz_setup(struct dsa_switch *ds)
>> dsa_switch_for_each_user_port(dp, dev->ds) {
>> ret = ksz_pirq_setup(dev, dp->index);
>> if (ret)
>> - goto out_girq;
>> + goto out_pirq;
>>
>> if (dev->info->ptp_capable) {
>> ret = ksz_ptp_irq_setup(ds, dp->index);
>> @@ -3083,10 +3083,8 @@ static int ksz_setup(struct dsa_switch *ds)
>> if (dev->ports[dp->index].pirq.domain)
>> ksz_irq_free(&dev->ports[dp->index].pirq);
>> }
>> - }
>> -out_girq:
>> - if (dev->irq > 0)
>> ksz_irq_free(&dev->girq);
>> + }
>>
>> return ret;
>> }
>>
>
> Looking at the code, I think it's still not enough, but feel free
> to correct me.
>
> In ksz_setup(), in one single loop we do :
>
> dsa_switch_for_each_user_port(dp, dev->ds) {
> ksz_pirq_setup();
>
> ksz_ptp_irq_setup();
> }
>
> However when anything fails in the above loop, we jump straight
> to out_pirq, which doesn't clean the ptpirq :(
Good catch, I should also merge together the out_ptpirq and out_pirq
labels then. And ensure that the PTP IRQ is initialized before freeing it.
I'll respin with that.
Best regards,
Bastien
next prev parent reply other threads:[~2025-11-17 18:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-17 13:05 [PATCH net v4 0/5] net: dsa: microchip: Fix resource releases in error path Bastien Curutchet (Schneider Electric)
2025-11-17 13:05 ` [PATCH net v4 1/5] net: dsa: microchip: common: Fix checks on irq_find_mapping() Bastien Curutchet (Schneider Electric)
2025-11-17 13:05 ` [PATCH net v4 2/5] net: dsa: microchip: ptp: " Bastien Curutchet (Schneider Electric)
2025-11-17 13:05 ` [PATCH net v4 3/5] net: dsa: microchip: Ensure a ksz_irq is initialized before freeing it Bastien Curutchet (Schneider Electric)
2025-11-17 13:05 ` [PATCH net v4 4/5] net: dsa: microchip: Free previously initialized ports on init failures Bastien Curutchet (Schneider Electric)
2025-11-17 16:28 ` Maxime Chevallier
2025-11-17 18:51 ` Bastien Curutchet [this message]
2025-11-17 13:05 ` [PATCH net v4 5/5] net: dsa: microchip: Fix symetry in ksz_ptp_msg_irq_{setup/free}() Bastien Curutchet (Schneider Electric)
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=bcd94483-281a-47e7-b82a-14064ad36129@bootlin.com \
--to=bastien.curutchet@bootlin.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=andrew@lunn.ch \
--cc=arun.ramadoss@microchip.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maxime.chevallier@bootlin.com \
--cc=miquel.raynal@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=pascal.eberhard@se.com \
--cc=richardcochran@gmail.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=woojung.huh@microchip.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®