Skip to content

Commit 3b5a611

Browse files
bastien-curutchetgregkh
authored andcommitted
net: dsa: microchip: Fix symetry in ksz_ptp_msg_irq_{setup/free}()
[ Upstream commit d0b8fec ] The IRQ numbers created through irq_create_mapping() are only assigned to ptpmsg_irq[n].num at the end of the IRQ setup. So if an error occurs between their creation and their assignment (for instance during the request_threaded_irq() step), we enter the error path and fail to release the newly created virtual IRQs because they aren't yet assigned to ptpmsg_irq[n].num. Move the mapping creation to ksz_ptp_msg_irq_setup() to ensure symetry with what's released by ksz_ptp_msg_irq_free(). In the error path, move the irq_dispose_mapping to the out_ptp_msg label so it will be called only on created IRQs. Cc: stable@vger.kernel.org Fixes: cc13ab1 ("net: dsa: microchip: ptp: enable interrupt for timestamping") Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: Bastien Curutchet (Schneider Electric) <bastien.curutchet@bootlin.com> Link: https://patch.msgid.link/20251120-ksz-fix-v6-5-891f80ae7f8f@bootlin.com Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 70ad645 commit 3b5a611

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

drivers/net/dsa/microchip/ksz_ptp.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,19 +1099,19 @@ static int ksz_ptp_msg_irq_setup(struct ksz_port *port, u8 n)
10991099
static const char * const name[] = {"pdresp-msg", "xdreq-msg",
11001100
"sync-msg"};
11011101
const struct ksz_dev_ops *ops = port->ksz_dev->dev_ops;
1102+
struct ksz_irq *ptpirq = &port->ptpirq;
11021103
struct ksz_ptp_irq *ptpmsg_irq;
11031104

11041105
ptpmsg_irq = &port->ptpmsg_irq[n];
1106+
ptpmsg_irq->num = irq_create_mapping(ptpirq->domain, n);
1107+
if (!ptpmsg_irq->num)
1108+
return -EINVAL;
11051109

11061110
ptpmsg_irq->port = port;
11071111
ptpmsg_irq->ts_reg = ops->get_port_addr(port->num, ts_reg[n]);
11081112

11091113
snprintf(ptpmsg_irq->name, sizeof(ptpmsg_irq->name), name[n]);
11101114

1111-
ptpmsg_irq->num = irq_find_mapping(port->ptpirq.domain, n);
1112-
if (ptpmsg_irq->num < 0)
1113-
return ptpmsg_irq->num;
1114-
11151115
return request_threaded_irq(ptpmsg_irq->num, NULL,
11161116
ksz_ptp_msg_thread_fn, IRQF_ONESHOT,
11171117
ptpmsg_irq->name, ptpmsg_irq);
@@ -1141,9 +1141,6 @@ int ksz_ptp_irq_setup(struct dsa_switch *ds, u8 p)
11411141
if (!ptpirq->domain)
11421142
return -ENOMEM;
11431143

1144-
for (irq = 0; irq < ptpirq->nirqs; irq++)
1145-
irq_create_mapping(ptpirq->domain, irq);
1146-
11471144
ptpirq->irq_num = irq_find_mapping(port->pirq.domain, PORT_SRC_PTP_INT);
11481145
if (!ptpirq->irq_num) {
11491146
ret = -EINVAL;
@@ -1165,12 +1162,11 @@ int ksz_ptp_irq_setup(struct dsa_switch *ds, u8 p)
11651162

11661163
out_ptp_msg:
11671164
free_irq(ptpirq->irq_num, ptpirq);
1168-
while (irq--)
1165+
while (irq--) {
11691166
free_irq(port->ptpmsg_irq[irq].num, &port->ptpmsg_irq[irq]);
1170-
out:
1171-
for (irq = 0; irq < ptpirq->nirqs; irq++)
11721167
irq_dispose_mapping(port->ptpmsg_irq[irq].num);
1173-
1168+
}
1169+
out:
11741170
irq_domain_remove(ptpirq->domain);
11751171

11761172
return ret;

0 commit comments

Comments
 (0)