Skip to content

Commit

Permalink
rpmsg_virtio: Do not make assumptions on struct member order
Browse files Browse the repository at this point in the history
In rpmsg_virtio_ns_callback() we directly case from rpmsg_device* to
rpmsg_virtio_device*. This only works if rdev is the first member.
Use metal_container_of() to remove this assumption on struct order.

Signed-off-by: Andrew Davis <afd@ti.com>
  • Loading branch information
glneo authored and arnopo committed Apr 9, 2024
1 parent 89a8a30 commit a5d7f13
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rpmsg/rpmsg_virtio.c
Expand Up @@ -657,7 +657,9 @@ static int rpmsg_virtio_ns_callback(struct rpmsg_endpoint *ept, void *data,
size_t len, uint32_t src, void *priv)
{
struct rpmsg_device *rdev = ept->rdev;
struct rpmsg_virtio_device *rvdev = (struct rpmsg_virtio_device *)rdev;
struct rpmsg_virtio_device *rvdev = metal_container_of(rdev,
struct rpmsg_virtio_device,
rdev);
struct metal_io_region *io = rvdev->shbuf_io;
struct rpmsg_endpoint *_ept;
struct rpmsg_ns_msg *ns_msg;
Expand Down

0 comments on commit a5d7f13

Please sign in to comment.