From: "Bastien Curutchet (Schneider Electric)" <bastien.curutchet@bootlin.com>
To: 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,
"Bastien Curutchet (Schneider Electric)"
<bastien.curutchet@bootlin.com>
Subject: [PATCH net v4 3/5] net: dsa: microchip: Ensure a ksz_irq is initialized before freeing it
Date: Mon, 17 Nov 2025 14:05:44 +0100 [thread overview]
Message-ID: <20251117-ksz-fix-v4-3-13e1da58a492@bootlin.com> (raw)
In-Reply-To: <20251117-ksz-fix-v4-0-13e1da58a492@bootlin.com>
If something goes wrong at setup, ksz_irq_free() can be called on
uninitialized ksz_irq (for example when ksz_ptp_irq_setup() fails). It
leads to freeing uninitialized IRQ numbers and/or domains.
Ensure that the ksz_irq is initialized before calling ksz_irq_free().
Fixes: cc13ab18b201 ("net: dsa: microchip: ptp: enable interrupt for timestamping")
Signed-off-by: Bastien Curutchet (Schneider Electric) <bastien.curutchet@bootlin.com>
--
Regarding the Fixes tag here, IMO before cc13ab18b201 it was safe to
not check the domain and the IRQ number because I don't see any path
where ksz_irq_free() would be called on a non-initialized ksz_irq
---
drivers/net/dsa/microchip/ksz_common.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index c724f5af5d98bf3ff784e36393dd5b3fa7b37c13..a622416d966330187ee062b2f44051ddf4ce2a78 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -3078,9 +3078,12 @@ static int ksz_setup(struct dsa_switch *ds)
dsa_switch_for_each_user_port(dp, dev->ds)
ksz_ptp_irq_free(ds, dp->index);
out_pirq:
- if (dev->irq > 0)
- dsa_switch_for_each_user_port(dp, dev->ds)
- ksz_irq_free(&dev->ports[dp->index].pirq);
+ if (dev->irq > 0) {
+ dsa_switch_for_each_user_port(dp, dev->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);
--
2.51.1
next prev parent reply other threads:[~2025-11-17 13:06 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 ` Bastien Curutchet (Schneider Electric) [this message]
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
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=20251117-ksz-fix-v4-3-13e1da58a492@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=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®