On Wed, Mar 10, 2021 at 07:11:07AM -0800, Richard Cochran wrote:
> On Wed, Mar 10, 2021 at 03:25:18PM +0100, Miroslav Lichvar wrote:
> > @@ -37,7 +38,7 @@ int assume_two_step = 0;
> > struct message_storage {
> > unsigned char reserved[MSG_HEADROOM];
> > struct ptp_message msg;
> > -} PACKED;
> > +};
>
> Is there a better way? How about dropping PACKED but adding an
> alignment attribute on 'msg'?
Like this?
struct message_storage {
unsigned char reserved[MSG_HEADROOM];
struct ptp_message msg __attribute__ ((aligned (8)));
};
>
> We don't about extra padding between 'reserved' and 'msg'.
Ok.
> > @@ -267,6 +268,10 @@ struct ptp_message *msg_allocate(void)
> > pool_stats.total++;
> > pool_debug("allocate", m);
> > }
> > + if (sizeof(s->reserved) + sizeof(s->msg) != sizeof(*s)) {
> > + pr_err("unexpected alignment");
> > + exit(1);
> > + }
>
> This is clunky. If we really _must_ have it, then it should be a one
> time check (msg_init()?) and not every time a message is allocated.
> But I would prefer avoiding this altogether.
It was meant as a protection against modification of the structure
that would leap to padding. It would normally be optimized away. But
if that is not a problem, I'll drop it.
--
Miroslav Lichvar
_______________________________________________
Linuxptp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel