[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <uj7g35pvelxwnukbkii6d7kzc4pjsj6wrtbcuomg3vhdluoxap@owoy3uy3xcrr>
Date: Tue, 25 Feb 2025 13:25:53 +0100
From: Peter Hilber <quic_philber@...cinc.com>
To: Simon Horman <horms@...nel.org>
CC: "Michael S. Tsirkin" <mst@...hat.com>, Jason Wang <jasowang@...hat.com>,
Trilok Soni <quic_tsoni@...cinc.com>,
Srivatsa Vaddagiri
<quic_svaddagi@...cinc.com>,
Xuan Zhuo <xuanzhuo@...ux.alibaba.com>,
Eugenio
PĂ©rez <eperezma@...hat.com>,
Richard Cochran
<richardcochran@...il.com>,
<linux-kernel@...r.kernel.org>, <virtualization@...ts.linux.dev>,
<netdev@...r.kernel.org>, David Woodhouse
<dwmw2@...radead.org>,
"Ridoux, Julien" <ridouxj@...zon.com>, Marc Zyngier
<maz@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Daniel Lezcano
<daniel.lezcano@...aro.org>,
Alexandre Belloni
<alexandre.belloni@...tlin.com>,
Parav Pandit <parav@...dia.com>,
"Matias
Ezequiel Vara Larsen" <mvaralar@...hat.com>,
Cornelia Huck
<cohuck@...hat.com>, <virtio-dev@...ts.linux.dev>,
<linux-arm-kernel@...ts.infradead.org>, <linux-rtc@...r.kernel.org>
Subject: Re: [PATCH v5 1/4] virtio_rtc: Add module and driver core
On Mon, Feb 24, 2025 at 05:55:27PM +0000, Simon Horman wrote:
> 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.
>
Thanks, I took a closer look and I think a virtio_le_to_cpu() inside the
typeof()s will both keep the sanity check working and keep sparse from
complaining - in the below case as well.
Peter
> > + \
> > + _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
> > + */
>
> ...
Powered by blists - more mailing lists