mirror of
https://github.com/apache/nuttx.git
synced 2026-05-22 05:42:05 +08:00
drivers/rpmsg: fix struct alignment issue by removing zero array member
This commit fixes a memory alignment issue in the rpmsg subsystem. The previous implementation used a flexible array member (rdev[0]) in struct rpmsg_s, but due to automatic 8-byte padding, rpmsg->rdev could differ from the transport layer's rdev address (e.g., rpmsg_virtio->rvdev.rdev), causing potential memory corruption. Changes: - Remove rdev[0] flexible array member from struct rpmsg_s - Add rpmsg_get_rdev_by_rpmsg() inline helper to calculate rdev address as (rpmsg + 1), ensuring correct pointer arithmetic - Update all rpmsg->rdev references to use the new helper function - Fix rpmsg_virtio_notify_wait() to use correct container_of macro Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
This commit is contained in:
committed by
Xiang Xiao
parent
fea492cf6f
commit
aa567d43f6
@@ -68,7 +68,6 @@ struct rpmsg_s
|
||||
struct rpmsg_endpoint test;
|
||||
#endif
|
||||
atomic_int signals;
|
||||
struct rpmsg_device rdev[0];
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -108,6 +107,17 @@ extern "C"
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
static inline FAR struct rpmsg_device *
|
||||
rpmsg_get_rdev_by_rpmsg(FAR struct rpmsg_s *rpmsg)
|
||||
{
|
||||
if (!rpmsg)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (FAR struct rpmsg_device *)(rpmsg + 1);
|
||||
}
|
||||
|
||||
int rpmsg_wait(FAR struct rpmsg_endpoint *ept, FAR sem_t *sem);
|
||||
int rpmsg_post(FAR struct rpmsg_endpoint *ept, FAR sem_t *sem);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user