Re: [PATCH v2 3/3] tty: n_gsm: add parameter negotiation support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> > > > +	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




[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux PPP]     [Linux FS]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Linmodem]     [Device Mapper]     [Linux Kernel for ARM]

  Powered by Linux