sched/irq: avoid casting from signed int to unsigned int

casting from signed int to unsigned int is not safe and should not be allowed

Signed-off-by: pangzhen1 <pangzhen1@xiaomi.com>
This commit is contained in:
pangzhen1
2025-08-11 20:19:36 +08:00
committed by Xiang Xiao
parent d9aaaaf1c7
commit 652b90f899
4 changed files with 7 additions and 7 deletions
+1 -1
View File
@@ -111,7 +111,7 @@ int irq_attach(int irq, xcpt_t isr, FAR void *arg)
#if NR_IRQS > 0 #if NR_IRQS > 0
int ret = -EINVAL; int ret = -EINVAL;
if ((unsigned)irq < NR_IRQS) if (irq >= 0 && irq < NR_IRQS)
{ {
int ndx = IRQ_TO_NDX(irq); int ndx = IRQ_TO_NDX(irq);
irqstate_t flags; irqstate_t flags;
+2 -2
View File
@@ -99,7 +99,7 @@ static int isr_thread_main(int argc, FAR char *argv[])
info.arg = arg; info.arg = arg;
info.handler = isr; info.handler = isr;
nxsem_init(&sem, 0, 0); nxsem_init(&sem, 0, 0u);
irq_attach(irq, irq_thread_default_handler, &info); irq_attach(irq, irq_thread_default_handler, &info);
@@ -159,7 +159,7 @@ int irq_attach_thread(int irq, xcpt_t isr, xcpt_t isrthread, FAR void *arg,
pid_t pid; pid_t pid;
int ndx; int ndx;
if ((unsigned)irq >= NR_IRQS) if (irq < 0 || irq >= NR_IRQS)
{ {
return -EINVAL; return -EINVAL;
} }
+2 -2
View File
@@ -138,7 +138,7 @@ static int irq_default_handler(int irq, FAR void *regs, FAR void *arg)
if (ret == IRQ_WAKE_THREAD) if (ret == IRQ_WAKE_THREAD)
{ {
work_queue_wq(info->wqueue, &info->work, irq_work_handler, info, 0); work_queue_wq(info->wqueue, &info->work, irq_work_handler, info, 0u);
ret = OK; ret = OK;
} }
@@ -179,7 +179,7 @@ int irq_attach_wqueue(int irq, xcpt_t isr, xcpt_t isrwork,
#if NR_IRQS > 0 #if NR_IRQS > 0
int ndx; int ndx;
if ((unsigned)irq >= NR_IRQS) if (irq < 0 || irq >= NR_IRQS)
{ {
return -EINVAL; return -EINVAL;
} }
+2 -2
View File
@@ -102,10 +102,10 @@ void irq_dispatch(int irq, FAR void *context)
#endif #endif
xcpt_t vector = irq_unexpected_isr; xcpt_t vector = irq_unexpected_isr;
FAR void *arg = NULL; FAR void *arg = NULL;
unsigned int ndx = irq; int ndx = irq;
#if NR_IRQS > 0 #if NR_IRQS > 0
if ((unsigned)irq < NR_IRQS) if (irq >= 0 && irq < NR_IRQS)
{ {
#ifdef CONFIG_ARCH_MINIMAL_VECTORTABLE #ifdef CONFIG_ARCH_MINIMAL_VECTORTABLE
ndx = g_irqmap[irq]; ndx = g_irqmap[irq];