[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 07/16] xen/riscv: introduce platform_get_irq()
- To: Jan Beulich <jbeulich@xxxxxxxx>
- From: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
- Date: Fri, 16 May 2025 16:04:03 +0200
- Cc: Alistair Francis <alistair.francis@xxxxxxx>, Bob Eshleman <bobbyeshleman@xxxxxxxxx>, Connor Davis <connojdavis@xxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Romain Caritey <Romain.Caritey@xxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
- Delivery-date: Fri, 16 May 2025 14:04:21 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 5/15/25 9:33 AM, Jan Beulich wrote:
+int platform_get_irq(const struct dt_device_node *device, int index)
+{
+ struct dt_irq dt_irq;
+ int ret;
+
+ if ( (ret = dt_device_get_irq(device, index, &dt_irq)) != 0 )
+ return ret;
+
+ if ( (ret = irq_set_type(dt_irq.irq, dt_irq.type)) != 0 )
+ return ret;
+
+ return dt_irq.irq;
What guarantees the value to be at most INT_MAX (i.e. no silent conversion to
a negative value, signaling an error to the caller)? Actually, looking at
irq_set_type(), what guarantees irq_to_desc() there to not overrun irq_desc[]?
There are no bounds checks in aplic_irq_xlate().
I'm afraid that both aren't guaranteed. I think to have the following in platform_get_irq()
should be enough:
BUILD_BUG_ON(NR_IRQS > INT_MAX);
if ( dt_irq.irq >= NR_IRQS )
panic("irq%d is bigger then NR_IRQS(%d)\n", dt_irq.irq, NR_IRQS);
Probably, the first could be dropped as I'm not sure that anyone will use such big
number for NR_IRQS.
~ Oleksii
|