mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Anatol Belski <weltling@outlook.de>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: byteorder: cpu_to_le32_array vs cpu_to_be32_array function API differences
Date: Sun, 20 Oct 2019 12:40:30 -0700	[thread overview]
Message-ID: <0f7518736a2508371fecf91db6e28d50494360b3.camel@perches.com> (raw)
In-Reply-To: <AM0PR0502MB3668C7B77C05918FF96EF10DBA6E0@AM0PR0502MB3668.eurprd05.prod.outlook.com>

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


  reply	other threads:[~2019-10-20 19:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-20 19:02 Joe Perches
2019-10-20 19:28 ` Anatol Belski
2019-10-20 19:40   ` Joe Perches [this message]
2019-10-20 20:23     ` Anatol Belski
2019-10-21  9:31 ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0f7518736a2508371fecf91db6e28d50494360b3.camel@perches.com \
    --to=joe@perches.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=weltling@outlook.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®