[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <GV1PR10MB5892C01AF7683B0E781C88D3E0319@GV1PR10MB5892.EURPRD10.PROD.OUTLOOK.COM>
Date: Tue, 25 Oct 2022 12:25:52 +0000
From: "Starke, Daniel" <daniel.starke@...mens.com>
To: Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>
CC: linux-serial <linux-serial@...r.kernel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Jiri Slaby <jirislaby@...nel.org>,
LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 3/3] tty: n_gsm: add parameter negotiation support
> > > > + n1 = FIELD_GET(PN_N_FIELD_N1, le16_to_cpu(params->n_bits));
> > >
> > > Should this be using get_unaligned...()?
> >
> > Is this really necessary if the structure is already __packed? I did not
> > receive any warning by the compiler.
>
> It would be arch dependent to begin with. But honestly, I'm not entirely
> certain here myself.
I have checked the code in include/asm-generic/unaligned.h.
An extract:
#define __get_unaligned_t(type, ptr) ({ \
const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
__pptr->x; \
})
#define get_unaligned(ptr) __get_unaligned_t(typeof(*(ptr)), (ptr))
static inline u16 get_unaligned_le16(const void *p)
{
return le16_to_cpu(__get_unaligned_t(__le16, p));
}
Looking at this I would assume that the use of get_unaligned_le16() makes
no difference compared to the current implementation. My assumption is
that the compiler makes sure the 16-bit value is accessed at the correct
address and le16_to_cpu() converts the intermediate value correctly.
> static_assert(sizeof(struct gsm_dlci_param_bits) == 8);
>
> If lkp builds all its current archs fine with that static_assert(), I'd be
> pretty sure the struct that the unpacked struct is ok on all archs. Would
> it ever stop being true on any arch/compiler setting, the assert would
> catch it right away.
That is an uncertainty I would like to avoid. And what should be the
solution if the assertion fails? Nevertheless, I do not mind implementing
it in this way to move forward.
Best regards,
Daniel Starke
Powered by blists - more mailing lists