Re: byteorder: cpu_to_le32_array vs cpu_to_be32_array function API differences

From: Anatol Belski
Date: Sun Oct 20 2019 - 15:29:07 EST


Hi,

On Sun, 2019-10-20 at 12:02 -0700, Joe Perches wrote:
> There's an argument inconsistency between these 4 functions
> in include/linux/byteorder/generic.h
>
> It'd be more a consistent API with one form and not two.
>
> static inline void le32_to_cpu_array(u32 *buf, unsigned int words)
> {
> while (words--) {
> __le32_to_cpus(buf);
> buf++;
> }
> }
>
> static inline void cpu_to_le32_array(u32 *buf, unsigned int words)
> {
> while (words--) {
> __cpu_to_le32s(buf);
> buf++;
> }
> }
>
> vs
>
> static inline void cpu_to_be32_array(__be32 *dst, const u32 *src,
> size_t len)
> {
> int i;
>
> for (i = 0; i < len; i++)
> dst[i] = cpu_to_be32(src[i]);
> }
>
> static inline void be32_to_cpu_array(u32 *dst, const __be32 *src,
> size_t len)
> {
> int i;
>
> for (i = 0; i < len; i++)
> dst[i] = be32_to_cpu(src[i]);
> }
>
>

size_t is the right choice for this, as it'll generate more correct
binary depending on 32/64 bit. I've sent a patch in
'include/linux/byteorder/generic.h: fix signed/unsigned warnings'
before, but only touched the place where i've seen warnings. My very
bet is, that changing between size_t/unsigned, while it would be
consistent, wouldn't change the functionality. It'd probably make sense
to extend the aforementioned patch to move unsigned -> size_t.

Regards

Anatol