Skip to content

Commit 53754ff

Browse files
authoredMar 2, 2024··
[fixup] check NULL pointer before access (#8573)
Signed-off-by: Shell <[email protected]>
1 parent 00c6800 commit 53754ff

File tree

7 files changed

+54
-31
lines changed

7 files changed

+54
-31
lines changed
 

‎bsp/qemu-virt64-aarch64/applications/main.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
*/
1010

1111
#include <stdio.h>
12+
#include <rtthread.h>
1213

1314
int main(void)
1415
{
15-
printf("hello rt-thread\n");
16+
rt_kprintf("hello rt-thread\n");
1617

1718
return 0;
1819
}

‎bsp/qemu-virt64-aarch64/drivers/secondary_cpu.c

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#include "mmu.h"
1515
#include "gtimer.h"
1616

17+
#ifdef BSP_USING_GICV3
18+
#include <gicv3.h>
19+
#endif
20+
1721
#ifdef RT_USING_SMP
1822

1923
extern unsigned long MMUTable[];
@@ -29,6 +33,10 @@ void rt_hw_secondary_cpu_bsp_start(void)
2933

3034
arm_gic_cpu_init(0, 0);
3135

36+
#ifdef BSP_USING_GICV3
37+
arm_gic_redist_init(0, 0);
38+
#endif /* BSP_USING_GICV3 */
39+
3240
// local timer init
3341
rt_hw_gtimer_init();
3442

‎components/mm/mm_aspace.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ int rt_aspace_load_page(rt_aspace_t aspace, void *addr, rt_size_t npage)
12781278

12791279
if (!varea)
12801280
{
1281-
LOG_W("%s: varea not exist", __func__);
1281+
LOG_W("%s: varea not exist(addr=%p)", __func__, addr);
12821282
err = -RT_ENOENT;
12831283
}
12841284
else if ((char *)addr >= end || (rt_size_t)addr & ARCH_PAGE_MASK ||

‎libcpu/aarch64/common/backtrace.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ rt_err_t rt_hw_backtrace_frame_unwind(rt_thread_t thread, struct rt_hw_backtrace
8585
if (fp && !((long)fp & 0x7))
8686
{
8787
#ifdef RT_USING_SMART
88-
if (thread->lwp)
88+
if (thread && thread->lwp)
8989
{
9090
rt_lwp_t lwp = thread->lwp;
9191
void *this_lwp = lwp_self();

‎libcpu/aarch64/common/gicv3.c

+30-25
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,24 @@ static unsigned int _gic_max_irq;
8181
#define ICC_ASGI1R_EL1 "S3_0_C12_C11_6"
8282

8383
/* Macro to access the Distributor Control Register (GICD_CTLR) */
84-
#define GICD_CTLR_RWP (1 << 31)
85-
#define GICD_CTLR_E1NWF (1 << 7)
86-
#define GICD_CTLR_DS (1 << 6)
87-
#define GICD_CTLR_ARE_NS (1 << 5)
88-
#define GICD_CTLR_ARE_S (1 << 4)
89-
#define GICD_CTLR_ENGRP1S (1 << 2)
90-
#define GICD_CTLR_ENGRP1NS (1 << 1)
91-
#define GICD_CTLR_ENGRP0 (1 << 0)
84+
#define GICD_CTLR_RWP (1U << 31)
85+
#define GICD_CTLR_E1NWF (1U << 7)
86+
#define GICD_CTLR_DS (1U << 6)
87+
#define GICD_CTLR_ARE_NS (1U << 5)
88+
#define GICD_CTLR_ARE_S (1U << 4)
89+
#define GICD_CTLR_ENGRP1S (1U << 2)
90+
#define GICD_CTLR_ENGRP1NS (1U << 1)
91+
#define GICD_CTLR_ENGRP0 (1U << 0)
9292

9393
/* Macro to access the Redistributor Control Register (GICR_CTLR) */
94-
#define GICR_CTLR_UWP (1 << 31)
95-
#define GICR_CTLR_DPG1S (1 << 26)
96-
#define GICR_CTLR_DPG1NS (1 << 25)
97-
#define GICR_CTLR_DPG0 (1 << 24)
98-
#define GICR_CTLR_RWP (1 << 3)
99-
#define GICR_CTLR_IR (1 << 2)
100-
#define GICR_CTLR_CES (1 << 1)
101-
#define GICR_CTLR_EnableLPI (1 << 0)
94+
#define GICR_CTLR_UWP (1U << 31)
95+
#define GICR_CTLR_DPG1S (1U << 26)
96+
#define GICR_CTLR_DPG1NS (1U << 25)
97+
#define GICR_CTLR_DPG0 (1U << 24)
98+
#define GICR_CTLR_RWP (1U << 3)
99+
#define GICR_CTLR_IR (1U << 2)
100+
#define GICR_CTLR_CES (1U << 1)
101+
#define GICR_CTLR_EnableLPI (1U << 0)
102102

103103
/* Macro to access the Generic Interrupt Controller Interface (GICC) */
104104
#define GIC_CPU_CTRL(hw_base) HWREG32((hw_base) + 0x00U)
@@ -162,7 +162,7 @@ static unsigned int _gic_max_irq;
162162

163163
int arm_gic_get_active_irq(rt_uint64_t index)
164164
{
165-
int irq;
165+
rt_base_t irq;
166166

167167
RT_ASSERT(index < ARM_GIC_MAX_NR);
168168

@@ -178,7 +178,7 @@ void arm_gic_ack(rt_uint64_t index, int irq)
178178
RT_ASSERT(irq >= 0);
179179

180180
__DSB();
181-
SET_GICV3_REG(ICC_EOIR1_EL1, irq);
181+
SET_GICV3_REG(ICC_EOIR1_EL1, (rt_base_t)irq);
182182
}
183183

184184
void arm_gic_mask(rt_uint64_t index, int irq)
@@ -397,7 +397,7 @@ void arm_gic_set_priority(rt_uint64_t index, int irq, rt_uint64_t priority)
397397
rt_int32_t cpu_id = rt_hw_cpu_id();
398398

399399
mask = GIC_RDISTSGI_IPRIORITYR(_gic_table[index].redist_hw_base[cpu_id], irq);
400-
mask &= ~(0xff << ((irq % 4) * 8));
400+
mask &= ~(0xffUL << ((irq % 4) * 8));
401401
mask |= ((priority & 0xff) << ((irq % 4) * 8));
402402
GIC_RDISTSGI_IPRIORITYR(_gic_table[index].redist_hw_base[cpu_id], irq) = mask;
403403
}
@@ -468,7 +468,7 @@ rt_uint64_t arm_gic_get_interface_prior_mask(rt_uint64_t index)
468468

469469
void arm_gic_set_binary_point(rt_uint64_t index, rt_uint64_t binary_point)
470470
{
471-
index = index;
471+
RT_UNUSED(index);
472472
binary_point &= 0x7;
473473

474474
SET_GICV3_REG(ICC_BPR1_EL1, binary_point);
@@ -478,7 +478,7 @@ rt_uint64_t arm_gic_get_binary_point(rt_uint64_t index)
478478
{
479479
rt_uint64_t binary_point;
480480

481-
index = index;
481+
RT_UNUSED(index);
482482
GET_GICV3_REG(ICC_BPR1_EL1, binary_point);
483483
return binary_point;
484484
}
@@ -616,7 +616,7 @@ rt_uint64_t arm_gic_get_high_pending_irq(rt_uint64_t index)
616616
rt_uint64_t irq;
617617
RT_ASSERT(index < ARM_GIC_MAX_NR);
618618

619-
index = index;
619+
RT_UNUSED(index);
620620
GET_GICV3_REG(ICC_HPPIR1_EL1, irq);
621621

622622
return irq;
@@ -625,13 +625,18 @@ rt_uint64_t arm_gic_get_high_pending_irq(rt_uint64_t index)
625625
rt_uint64_t arm_gic_get_interface_id(rt_uint64_t index)
626626
{
627627
rt_uint64_t ret = 0;
628+
rt_base_t level;
629+
int cpuid;
628630

629631
RT_ASSERT(index < ARM_GIC_MAX_NR);
630632

631-
if (_gic_table[index].cpu_hw_base != RT_NULL)
633+
level = rt_hw_local_irq_disable();
634+
cpuid = rt_hw_cpu_id();
635+
if (_gic_table[index].cpu_hw_base[cpuid] != RT_NULL)
632636
{
633-
ret = GIC_CPU_IIDR(_gic_table[index].cpu_hw_base);
637+
ret = GIC_CPU_IIDR(_gic_table[index].cpu_hw_base[cpuid]);
634638
}
639+
rt_hw_local_irq_enable(level);
635640

636641
return ret;
637642
}
@@ -857,7 +862,7 @@ int arm_gic_cpu_init(rt_uint64_t index, rt_uint64_t cpu_base)
857862
value = arm_gic_get_system_register_enable_mask(index);
858863
value |= (1 << 0);
859864
arm_gic_set_system_register_enable_mask(index, value);
860-
SET_GICV3_REG(ICC_CTLR_EL1, 0);
865+
SET_GICV3_REG(ICC_CTLR_EL1, 0l);
861866

862867
arm_gic_set_interface_prior_mask(index, 0xff);
863868

‎libcpu/aarch64/common/setup.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,10 @@ void rt_hw_common_setup(void)
390390

391391
for (int i = 0; i < mem_region_nr; ++i, ++mem_region)
392392
{
393-
if (mem_region != page_region)
393+
if (mem_region != page_region && mem_region->name)
394394
{
395+
mem_region->start -= PV_OFFSET;
396+
mem_region->end -= PV_OFFSET;
395397
rt_page_install(*mem_region);
396398
}
397399
}

‎src/scheduler_mp.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -1255,8 +1255,15 @@ rt_uint16_t rt_critical_level(void)
12551255

12561256
current_thread = rt_cpu_self()->current_thread;
12571257

1258-
/* the necessary memory barrier is done on irq_(dis|en)able */
1259-
critical_lvl = RT_SCHED_CTX(current_thread).critical_lock_nest;
1258+
if (current_thread)
1259+
{
1260+
/* the necessary memory barrier is done on irq_(dis|en)able */
1261+
critical_lvl = RT_SCHED_CTX(current_thread).critical_lock_nest;
1262+
}
1263+
else
1264+
{
1265+
critical_lvl = 0;
1266+
}
12601267

12611268
rt_hw_local_irq_enable(level);
12621269
return critical_lvl;

0 commit comments

Comments
 (0)
Please sign in to comment.