Skip to content

Commit

Permalink
kernel: userspace: Fix address-of-packed-mem warning
Browse files Browse the repository at this point in the history
The warning below appears once -Waddress-of-packed-mem is enabled:

/home/carles/src/zephyr/zephyr/kernel/userspace.c: In function
'unref_check':
/home/carles/src/zephyr/zephyr/kernel/userspace.c:471:28: warning:
converting a packed 'struct z_object' pointer (alignment 4) to a 'struct
dyn_obj' pointer (alignment 16) may result in an unaligned pointer value
[-Waddress-of-packed-mem
ber]
  471 |    CONTAINER_OF(ko, struct dyn_obj, kobj);

To avoid the warning, use an intermediate void * variable.

More info in zephyrproject-rtos#16587.

Signed-off-by: Carles Cufi <[email protected]>
  • Loading branch information
carlescufi committed Dec 10, 2021
1 parent 2000cdf commit 55350a9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions kernel/userspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,11 @@ static void unref_check(struct z_object *ko, uintptr_t index)
sys_bitfield_clear_bit((mem_addr_t)&ko->perms, index);

#ifdef CONFIG_DYNAMIC_OBJECTS
struct dyn_obj *dyn =
CONTAINER_OF(ko, struct dyn_obj, kobj);
void *vko = ko;

struct dyn_obj *dyn = CONTAINER_OF(vko, struct dyn_obj, kobj);
/* TODO: check why this assert hits */
/*__ASSERT(IS_PTR_ALIGNED(dyn, struct dyn_obj), "unaligned z_object");*/

if ((ko->flags & K_OBJ_FLAG_ALLOC) == 0U) {
goto out;
Expand Down

0 comments on commit 55350a9

Please sign in to comment.