[PATCH v5 1/4] virtio_rtc: Add module and driver core
Simon Horman
horms at kernel.org
Mon Feb 24 09:55:27 PST 2025
On Wed, Feb 19, 2025 at 08:32:56PM +0100, Peter Hilber wrote:
...
> +/**
> + * VIORTC_MSG() - extract message from message handle
> + * @hdl: message handle
> + *
> + * Return: struct viortc_msg
> + */
> +#define VIORTC_MSG(hdl) ((hdl).msg)
> +
> +/**
> + * VIORTC_MSG_INIT() - initialize message handle
> + * @hdl: message handle
> + * @viortc: device data (struct viortc_dev *)
> + *
> + * Context: Process context.
> + * Return: 0 on success, -ENOMEM otherwise.
> + */
> +#define VIORTC_MSG_INIT(hdl, viortc) \
> + ({ \
> + typeof(hdl) *_hdl = &(hdl); \
> + \
> + _hdl->msg = viortc_msg_init((viortc), _hdl->msg_type, \
> + _hdl->req_size, _hdl->resp_cap); \
> + if (_hdl->msg) { \
> + _hdl->req = _hdl->msg->req; \
> + _hdl->resp = _hdl->msg->resp; \
> + } \
> + _hdl->msg ? 0 : -ENOMEM; \
> + })
> +
> +/**
> + * VIORTC_MSG_WRITE() - write a request message field
> + * @hdl: message handle
> + * @dest_member: request message field name
> + * @src_ptr: pointer to data of compatible type
> + *
> + * Writes the field in little-endian format.
> + */
> +#define VIORTC_MSG_WRITE(hdl, dest_member, src_ptr) \
> + do { \
> + typeof(hdl) _hdl = (hdl); \
> + typeof(src_ptr) _src_ptr = (src_ptr); \
> + \
> + /* Sanity check: must match the member's type */ \
> + typecheck(typeof(_hdl.req->dest_member), *_src_ptr); \
Hi Peter,
FWIIW, this trips up sparse because from it's perspective
there is an endianness mismatch between the two types.
> + \
> + _hdl.req->dest_member = \
> + virtio_cpu_to_le(*_src_ptr, _hdl.req->dest_member); \
> + } while (0)
> +
> +/**
> + * VIORTC_MSG_READ() - read from a response message field
> + * @hdl: message handle
> + * @src_member: response message field name
> + * @dest_ptr: pointer to data of compatible type
> + *
> + * Converts from little-endian format and writes to dest_ptr.
> + */
> +#define VIORTC_MSG_READ(hdl, src_member, dest_ptr) \
> + do { \
> + typeof(dest_ptr) _dest_ptr = (dest_ptr); \
> + \
> + /* Sanity check: must match the member's type */ \
> + typecheck(typeof((hdl).resp->src_member), *_dest_ptr); \
Ditto.
> + \
> + *_dest_ptr = virtio_le_to_cpu((hdl).resp->src_member); \
> + } while (0)
> +
> +/*
> + * read requests
> + */
...
More information about the linux-arm-kernel
mailing list