Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arch: coding guidelines: use bool param when data nature is boolean #72675

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arch/arc/core/mpu/arc_core_mpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int arch_mem_domain_max_partitions_get(void)
/*
* Validate the given buffer is user accessible or not
*/
int arch_buffer_validate(const void *addr, size_t size, int write)
int arch_buffer_validate(const void *addr, size_t size, bool write)
{
return arc_core_mpu_buffer_validate(addr, size, write);
}
Expand Down
2 changes: 1 addition & 1 deletion arch/arc/core/mpu/arc_mpu_common_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ int arc_core_mpu_get_max_domain_partition_regions(void)
/**
* @brief validate the given buffer is user accessible or not
*/
int arc_core_mpu_buffer_validate(const void *addr, size_t size, int write)
int arc_core_mpu_buffer_validate(const void *addr, size_t size, bool write)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function calls _is_user_accessible_region, shouldn't that be updated as well?

Copy link
Collaborator

@evgeniy-paltsev evgeniy-paltsev May 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to update _is_user_accessible_region (which is called from arc_core_mpu_buffer_validate) as well.

Currently it's defined as

static inline bool _is_user_accessible_region(uint32_t r_index, int write)

{
/*
* For ARC MPU, smaller region number takes priority.
Expand Down
2 changes: 1 addition & 1 deletion arch/arc/core/mpu/arc_mpu_v4_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ int arc_core_mpu_get_max_domain_partition_regions(void)
/**
* @brief validate the given buffer is user accessible or not
*/
int arc_core_mpu_buffer_validate(const void *addr, size_t size, int write)
int arc_core_mpu_buffer_validate(const void *addr, size_t size, bool write)
{
int r_index;
int key = arch_irq_lock();
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/core/mpu/arm_core_mpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ int arch_mem_domain_max_partitions_get(void)
return ARM_CORE_MPU_MAX_DOMAIN_PARTITIONS_GET(available_regions);
}

int arch_buffer_validate(const void *addr, size_t size, int write)
int arch_buffer_validate(const void *addr, size_t size, bool write)
{
return arm_core_mpu_buffer_validate(addr, size, write);
}
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/core/mpu/arm_core_mpu_dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ int arm_core_mpu_get_max_available_dyn_regions(void);
* spans multiple enabled MPU regions (even if these regions all
* permit user access).
*/
int arm_core_mpu_buffer_validate(const void *addr, size_t size, int write);
int arm_core_mpu_buffer_validate(const void *addr, size_t size, bool write);

#endif /* CONFIG_ARM_MPU */

Expand Down
2 changes: 1 addition & 1 deletion arch/arm/core/mpu/arm_mpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ int arm_core_mpu_get_max_available_dyn_regions(void)
*
* Presumes the background mapping is NOT user accessible.
*/
int arm_core_mpu_buffer_validate(const void *addr, size_t size, int write)
int arm_core_mpu_buffer_validate(const void *addr, size_t size, bool write)
{
return mpu_buffer_validate(addr, size, write);
}
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/core/mpu/arm_mpu_v7_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ static inline int is_user_accessible_region(uint32_t r_index, int write)
* This internal function validates whether a given memory buffer
* is user accessible or not.
*/
static inline int mpu_buffer_validate(const void *addr, size_t size, int write)
static inline int mpu_buffer_validate(const void *addr, size_t size, bool write)
{
int32_t r_index;
int rc = -EPERM;
Expand Down
4 changes: 2 additions & 2 deletions arch/arm/core/mpu/arm_mpu_v8_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ static inline int is_user_accessible_region(uint32_t rnr, int write)
* This internal function validates whether a given memory buffer
* is user accessible or not.
*/
static inline int mpu_buffer_validate(const void *addr, size_t size, int write)
static inline int mpu_buffer_validate(const void *addr, size_t size, bool write)
{
int32_t rnr;
int rc = -EPERM;
Expand Down Expand Up @@ -455,7 +455,7 @@ static inline int mpu_buffer_validate(const void *addr, size_t size, int write)
* in case the fast address range check fails.
*
*/
static inline int mpu_buffer_validate(const void *addr, size_t size, int write)
static inline int mpu_buffer_validate(const void *addr, size_t size, bool write)
{
uint32_t _addr = (uint32_t)addr;
uint32_t _size = (uint32_t)size;
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/core/mpu/nxp_mpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ static inline int is_user_accessible_region(uint32_t r_index, int write)
/**
* @brief validate the given buffer is user accessible or not
*/
int arm_core_mpu_buffer_validate(const void *addr, size_t size, int write)
int arm_core_mpu_buffer_validate(const void *addr, size_t size, bool write)
{
uint8_t r_index;

Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/core/userspace.S
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ strlen_done:
ret

/*
* int arch_buffer_validate(const void *addr, size_t size, int write)
* int arch_buffer_validate(const void *addr, size_t size, bool write)
*/

GTEXT(arch_buffer_validate)
Expand Down
2 changes: 1 addition & 1 deletion arch/riscv/core/pmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ int arch_mem_domain_thread_remove(struct k_thread *thread)
((inner_start) >= (outer_start) && (inner_size) <= (outer_size) && \
((inner_start) - (outer_start)) <= ((outer_size) - (inner_size)))

int arch_buffer_validate(const void *addr, size_t size, int write)
int arch_buffer_validate(const void *addr, size_t size, bool write)
{
uintptr_t start = (uintptr_t)addr;
int ret = -1;
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/core/x86_mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ static inline void bcb_fence(void)
}

__pinned_func
int arch_buffer_validate(const void *addr, size_t size, int write)
int arch_buffer_validate(const void *addr, size_t size, bool write)
{
pentry_t *ptables = z_x86_thread_page_tables_get(_current);
uint8_t *virt;
Expand Down
2 changes: 1 addition & 1 deletion arch/xtensa/core/mpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ int arch_mem_domain_thread_remove(struct k_thread *thread)
return ret;
}

int arch_buffer_validate(const void *addr, size_t size, int write)
int arch_buffer_validate(const void *addr, size_t size, bool write)
{
uintptr_t aligned_addr;
size_t aligned_size, addr_offset;
Expand Down
2 changes: 1 addition & 1 deletion arch/xtensa/core/ptables.c
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ static bool page_validate(uint32_t *ptables, uint32_t page, uint8_t ring, bool w
return true;
}

int arch_buffer_validate(const void *addr, size_t size, int write)
int arch_buffer_validate(const void *addr, size_t size, bool write)
{
int ret = 0;
uint8_t *virt;
Expand Down
2 changes: 1 addition & 1 deletion include/zephyr/arch/arc/v2/mpu/arc_core_mpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void arc_core_mpu_remove_mem_domain(struct k_mem_domain *mem_domain);
void arc_core_mpu_remove_mem_partition(struct k_mem_domain *domain,
uint32_t partition_id);
int arc_core_mpu_get_max_domain_partition_regions(void);
int arc_core_mpu_buffer_validate(const void *addr, size_t size, int write);
int arc_core_mpu_buffer_validate(const void *addr, size_t size, bool write);

#endif

Expand Down
4 changes: 2 additions & 2 deletions include/zephyr/arch/arch_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -778,12 +778,12 @@ int arch_mem_domain_partition_add(struct k_mem_domain *domain,
*
* @param addr start address of the buffer
* @param size the size of the buffer
* @param write If non-zero, additionally check if the area is writable.
* @param write If true, additionally check if the area is writable.
* Otherwise, just check if the memory can be read.
*
* @return nonzero if the permissions don't match.
*/
int arch_buffer_validate(const void *addr, size_t size, int write);
int arch_buffer_validate(const void *addr, size_t size, bool write);

/**
* Get the optimal virtual region alignment to optimize the MMU table layout
Expand Down
Loading