Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: dsa: microchip: Fix symetry in ksz_ptp_msg_irq_{setup/free}()

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: cc13ab18b201 ("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>

authored by

Bastien Curutchet (Schneider Electric) and committed by
Paolo Abeni
d0b8fec8 0f80e21b

+7 -11
+7 -11
drivers/net/dsa/microchip/ksz_ptp.c
··· 1093 1093 static const char * const name[] = {"pdresp-msg", "xdreq-msg", 1094 1094 "sync-msg"}; 1095 1095 const struct ksz_dev_ops *ops = port->ksz_dev->dev_ops; 1096 + struct ksz_irq *ptpirq = &port->ptpirq; 1096 1097 struct ksz_ptp_irq *ptpmsg_irq; 1097 1098 1098 1099 ptpmsg_irq = &port->ptpmsg_irq[n]; 1100 + ptpmsg_irq->num = irq_create_mapping(ptpirq->domain, n); 1101 + if (!ptpmsg_irq->num) 1102 + return -EINVAL; 1099 1103 1100 1104 ptpmsg_irq->port = port; 1101 1105 ptpmsg_irq->ts_reg = ops->get_port_addr(port->num, ts_reg[n]); 1102 1106 1103 1107 strscpy(ptpmsg_irq->name, name[n]); 1104 - 1105 - ptpmsg_irq->num = irq_find_mapping(port->ptpirq.domain, n); 1106 - if (ptpmsg_irq->num < 0) 1107 - return ptpmsg_irq->num; 1108 1108 1109 1109 return request_threaded_irq(ptpmsg_irq->num, NULL, 1110 1110 ksz_ptp_msg_thread_fn, IRQF_ONESHOT, ··· 1135 1135 if (!ptpirq->domain) 1136 1136 return -ENOMEM; 1137 1137 1138 - for (irq = 0; irq < ptpirq->nirqs; irq++) 1139 - irq_create_mapping(ptpirq->domain, irq); 1140 - 1141 1138 ptpirq->irq_num = irq_find_mapping(port->pirq.domain, PORT_SRC_PTP_INT); 1142 1139 if (!ptpirq->irq_num) { 1143 1140 ret = -EINVAL; ··· 1156 1159 1157 1160 out_ptp_msg: 1158 1161 free_irq(ptpirq->irq_num, ptpirq); 1159 - while (irq--) 1162 + while (irq--) { 1160 1163 free_irq(port->ptpmsg_irq[irq].num, &port->ptpmsg_irq[irq]); 1161 - out: 1162 - for (irq = 0; irq < ptpirq->nirqs; irq++) 1163 1164 irq_dispose_mapping(port->ptpmsg_irq[irq].num); 1164 - 1165 + } 1166 + out: 1165 1167 irq_domain_remove(ptpirq->domain); 1166 1168 1167 1169 return ret;