Re: [PATCH 2/4] iio: imu: add Bosch Sensortec BNO055 core driver

Andrea Merello
2021-07-19T10:33:32Z

> > > > + for (i = 0; i < 4; i++)
> > > > + vals[i] = (s16)le16_to_cpu(raw_vals[i]);
> > >
> > > Extract this to be a helper like there are for u32 and u64.
> >
> > Could you please point me to those helpers? I don't know what you are
> > referring to.
>
> Read include/linux/byteorder/generic.h to the end.

I realized that implementing an helper like the other ones wouldn't
work in this specific case: I'd say a reasonable helper would take a
ptr to a s16 as its destination argument, but here we are assigning to
a int vector; so our brand new helper would be of no use here.

What I can do is to implement a macroized helper that would have no
issues wrt ptr type; I guess something like this:

#define le16_to_cpu_signed_array(dst, src, len) \
({ \
size_t __i; \
for (__i = 0; __i < len; __i++) \
dst[__i] = (s16)le16_to_cpu(src[__i]); \
})

What's your opinion here? should I go with something like this or do
you prefer to let the open-coded implementation stay in this specific
case?