All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
To: "Daniel W. S. Almeida" <dwlsalmeida@gmail.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-media@vger.kernel.org" <linux-media@vger.kernel.org>
Subject: Re: [PATCH RFC 06/11] media: vidtv: get rid of some endiannes nonsense
Date: Tue, 15 Sep 2020 13:49:23 +0200	[thread overview]
Message-ID: <20200915134923.4794f704@coco.lan> (raw)
In-Reply-To: <68DDA2DD-4341-45A9-99CF-BF41573C9AED@getmailspring.com>

Hi Daniel,

Em Mon, 14 Sep 2020 12:14:38 -0300
"Daniel W. S. Almeida" <dwlsalmeida@gmail.com> escreveu:

> Hi Mauro,
> 
> > Genmask is always highest order to low order. It doesn't make
> > any sense to make it depends on endiannes.
> >   
> 
> I added these #ifdefs due to this:
> 
> https://lwn.net/Articles/741762/
> 
> i.e.
> 
> Fields to access are specified as GENMASK() values - an N-bit field
> starting at bit #M is encoded as GENMASK(M + N - 1, N).  Note that
> bit numbers refer to endianness of the object we are working with -
> e.g. GENMASK(11, 0) in __be16 refers to the second byte and the lower
> 4 bits of the first byte.  In __le16 it would refer to the first byte
> and the lower 4 bits of the second byte, etc.
> 
> I am not 100% sure, but maybe we actually need them? 

By looking at the changes you did with regards to bitfields,
it sounds that you didn't quite get how BE/LE works.

Basically, if the CPU needs to store a value (like 0x8001) on some 
place, it will store two values: 0x80 and 0x01. Depending on the
endiannes, either 0x80 or 0x01 will be stored first. See:

	https://en.wikipedia.org/wiki/Endianness

In any case, when you do something like:

	mask = GENMASK(11, 0);
	ret = be16_to_cpu(s->bitfield) & mask;

The be16_to_cpu() will ensure that the bits will be at the
position expected by the CPU endiannes. So, no need to check
for __BIG_ENDIAN or __LITTLE_ENDIAN when be*_to_cpu() macros 
are used.

Please also notice that, when there's just one byte to be
stored (e. g. 8 bits), the endiannes won't matter, as the bits 
will still be stored at the same way. that's why there's no
be8_to_cpu() or cpu_to_be8() macros.

Thanks,
Mauro

  reply	other threads:[~2020-09-15 11:51 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-14  9:03 [PATCH RFC 00/11] Solve some issues and do some improvements at vidtv Mauro Carvalho Chehab
2020-09-14  9:03 ` [PATCH RFC 01/11] media: vidtv: add modaliases for the bridge driver Mauro Carvalho Chehab
2020-09-14  9:03 ` [PATCH RFC 02/11] media: vidtv: prefer using dev_foo() instead of pr_foo() Mauro Carvalho Chehab
2020-09-14  9:03 ` [PATCH RFC 03/11] media: vidtv: fix 32-bit warnings Mauro Carvalho Chehab
2020-09-14  9:03 ` [PATCH RFC 04/11] media: vidtv: fix frequency tuning logic Mauro Carvalho Chehab
2020-09-14  9:03 ` [PATCH RFC 05/11] media: vidtv: add an initial channel frequency Mauro Carvalho Chehab
2020-09-14  9:03 ` [PATCH RFC 06/11] media: vidtv: get rid of some endiannes nonsense Mauro Carvalho Chehab
2020-09-14 15:14   ` Daniel W. S. Almeida
2020-09-15 11:49     ` Mauro Carvalho Chehab [this message]
2020-09-14  9:03 ` [PATCH RFC 07/11] media: vidtv: remove a wrong endiannes check from s302m generator Mauro Carvalho Chehab
2020-09-16 18:13   ` kernel test robot
2020-09-16 18:13     ` kernel test robot
2020-09-14  9:03 ` [PATCH RFC 08/11] media: vidtv: properly initialize the internal state struct Mauro Carvalho Chehab
2020-09-14  9:03 ` [PATCH RFC 09/11] media: vidtv: add basic support for DVBv5 stats Mauro Carvalho Chehab
2020-09-14  9:03 ` [PATCH RFC 10/11] media: vidtv: get rid of the work queue Mauro Carvalho Chehab
2020-09-14  9:03 ` [PATCH RFC 11/11] media: vidtv: increment byte and block counters Mauro Carvalho Chehab

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=20200915134923.4794f704@coco.lan \
    --to=mchehab+huawei@kernel.org \
    --cc=dwlsalmeida@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    /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 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.