All of lore.kernel.org
 help / color / mirror / Atom feed
* byteorder: cpu_to_le32_array vs cpu_to_be32_array function API differences
@ 2019-10-20 19:02 Joe Perches
  2019-10-20 19:28 ` Anatol Belski
  2019-10-21  9:31 ` Andy Shevchenko
  0 siblings, 2 replies; 5+ messages in thread
From: Joe Perches @ 2019-10-20 19:02 UTC (permalink / raw)
  To: Andy Shevchenko, Herbert Xu, Mika Westerberg; +Cc: linux-kernel

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]);
   }

Added via 2 different commits:

commit f2f2efb807d339513199b1bb771806c90cce83ae
Author: Mika Westerberg <mika.westerberg@linux.intel.com>
Date:   Mon Oct 2 13:38:28 2017 +0300

    byteorder: Move {cpu_to_be32, be32_to_cpu}_array() from Thunderbolt to core
    
    We will be using these when communicating XDomain discovery protocol
    over Thunderbolt link but they might be useful for other drivers as
    well.
    
    Make them available through byteorder/generic.h.
    
    Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

and

commit 9def051018c08e65c532822749e857eb4b2e12e7
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date:   Wed Mar 21 19:01:40 2018 +0200

    crypto: Deduplicate le32_to_cpu_array() and cpu_to_le32_array()
    
    Deduplicate le32_to_cpu_array() and cpu_to_le32_array() by moving them
    to the generic header.
    
    No functional change implied.
    
    Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: byteorder: cpu_to_le32_array vs cpu_to_be32_array function API differences
  2019-10-20 19:02 byteorder: cpu_to_le32_array vs cpu_to_be32_array function API differences Joe Perches
@ 2019-10-20 19:28 ` Anatol Belski
  2019-10-20 19:40   ` Joe Perches
  2019-10-21  9:31 ` Andy Shevchenko
  1 sibling, 1 reply; 5+ messages in thread
From: Anatol Belski @ 2019-10-20 19:28 UTC (permalink / raw)
  To: Joe Perches, Andy Shevchenko, Herbert Xu, Mika Westerberg; +Cc: linux-kernel

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: byteorder: cpu_to_le32_array vs cpu_to_be32_array function API differences
  2019-10-20 19:28 ` Anatol Belski
@ 2019-10-20 19:40   ` Joe Perches
  2019-10-20 20:23     ` Anatol Belski
  0 siblings, 1 reply; 5+ messages in thread
From: Joe Perches @ 2019-10-20 19:40 UTC (permalink / raw)
  To: Anatol Belski, Andy Shevchenko, Herbert Xu, Mika Westerberg; +Cc: linux-kernel

On Sun, 2019-10-20 at 19:28 +0000, Anatol Belski wrote:
> Hi,

Hello.

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

True, but my point was the le versions have 2 arguments and
convert the buf input, and the be versions have 3 arguments
and convert src to dst.

cheers, Joe


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: byteorder: cpu_to_le32_array vs cpu_to_be32_array function API differences
  2019-10-20 19:40   ` Joe Perches
@ 2019-10-20 20:23     ` Anatol Belski
  0 siblings, 0 replies; 5+ messages in thread
From: Anatol Belski @ 2019-10-20 20:23 UTC (permalink / raw)
  To: Joe Perches, Andy Shevchenko, Herbert Xu, Mika Westerberg; +Cc: linux-kernel

On Sun, 2019-10-20 at 12:40 -0700, Joe Perches wrote:
> On Sun, 2019-10-20 at 19:28 +0000, Anatol Belski wrote:
> > Hi,
> 
> Hello.
> 
> > 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.
> 
> True, but my point was the le versions have 2 arguments and
> convert the buf input, and the be versions have 3 arguments
> and convert src to dst.

Thanks for checking. Yes, that's another point of the inconsistency. I
could imagine fixing it by adapting all the signatures to be


static inline void _cpu_to_le32_array(__le32 *dst, const u32 *src,
size_t len)
static inline void _le32_to_cpu_array(u32 *dst, const __le32 *src,
size_t len)
static inline void cpu_to_be32_array(__be32 *dst, const u32 *src,
size_t len)
static inline void be32_to_cpu_array(u32 *dst, const __be32 *src,
size_t len)

and do the necessary implementation change in the le variants, plus
introduce some macros to ensure the backward compatibility.

#define le32_to_cpu_array(dst, len) _cpu_to_le32_array(dst, dst, len)
#define cpu_to_le32_array(dst, len) _le32_to_cpu_array(dst, dst, len)

But it is a bad situation for the backward compatibility in any case,
as the new API would have to be named somehow. That would be bad for
the backport. If breaching this is ok for master, then the fix would be
as easy as changing the signatures and adapting the implementation.


Thanks

Anatol



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: byteorder: cpu_to_le32_array vs cpu_to_be32_array function API differences
  2019-10-20 19:02 byteorder: cpu_to_le32_array vs cpu_to_be32_array function API differences Joe Perches
  2019-10-20 19:28 ` Anatol Belski
@ 2019-10-21  9:31 ` Andy Shevchenko
  1 sibling, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2019-10-21  9:31 UTC (permalink / raw)
  To: Joe Perches; +Cc: Herbert Xu, Mika Westerberg, linux-kernel

On Sun, Oct 20, 2019 at 12:02:52PM -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.

This is done in order to:
 - avoid changing existing code
 - start a very this discussion to see what we can do if it's even needed to be done

So, do we have other places in the kernel which can utilize either of these?

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-10-21  9:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-20 19:02 byteorder: cpu_to_le32_array vs cpu_to_be32_array function API differences Joe Perches
2019-10-20 19:28 ` Anatol Belski
2019-10-20 19:40   ` Joe Perches
2019-10-20 20:23     ` Anatol Belski
2019-10-21  9:31 ` Andy Shevchenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.