public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Artem Bityutskiy <dedekind1@gmail.com>
To: Brian Norris <computersforpeace@gmail.com>
Cc: Mike Frysinger <vapier.adi@gmail.com>,
	Kevin Cernekee <cernekee@gmail.com>,
	b35362@freescale.com, linux-mtd@lists.infradead.org,
	David Woodhouse <dwmw2@infradead.org>,
	Matthew Creech <mlcreech@gmail.com>
Subject: Re: [RFC 4/5] mtd: move mtd_oob_mode_t to shared kernel/user space
Date: Tue, 23 Aug 2011 08:30:23 +0300	[thread overview]
Message-ID: <1314077429.2645.31.camel@sauron> (raw)
In-Reply-To: <CAN8TOE97XijzxpdjF4MHMzGhoAYw7VaLaYSD-HEP-UYUUCf13w@mail.gmail.com>

On Mon, 2011-08-22 at 14:43 -0700, Brian Norris wrote:
> On Mon, Aug 22, 2011 at 1:50 AM, Artem Bityutskiy <dedekind1@gmail.com> wrote:
> > On Wed, 2011-08-17 at 16:50 -0700, Brian Norris wrote:
> >> +typedef enum {
> >> +     MTD_OOB_PLACE,
> >> +     MTD_OOB_AUTO,
> >> +     MTD_OOB_RAW,
> >> +} mtd_oob_mode_t;
> >
> > Could we get rid of this typedef and use anonymous enum instead:
> >
> > enum {
> >        A,
> >        B,
> > };
> >
> > Indeed, we do not need it, and we do not want to pollute the user-space
> > namespaces unnecessarily.
> 
> Well, we do *use* the typedef in a few kernel structs, and we will use
> it in user space as well. So we may run into issues with 32-bit vs.
> 64-bit integers if we just stick with an int-based type, right?

I just find typedefs unreadable. Every time you see it - you need to
look at the definition, find it, distract. And C does not do any type
checking anway, so typedefs for enums really make little sense. If you
really do not want to use int, let's use 'enum blah' type, which is at
least readable - when you see it - you know it is just an integer, and
you do not have to find the definition.

Anonymous enums is my preference. They are just like macro definition,
but with assumed type, and potentially debugger-friendly.

So, to conclude:

1. typedefs for enums make no sense a all - C does not do any strict
type-checking anyway, and typedefs only make reading code more
difficult.

2. using 'enum blah' is more sensible - it does not hurt readability too
much at least.

3. IMHO, and I even dare to say that many kernel gurus would agree, if
we are talking about a simple enum with just few constants inside -
anonymous enum is the best - the code is simpler and more readable.

It is not that difficult to remove in-kernel usage of typedefs, I think.
VS user-space - the only user we care about - mtd-utils - has its own
copy of the headers, and if we update the header files there, we can
amend mtd-utils.

32/64 problems - what do you mean? enumeration = 'int' which is always
32 bits in all architectures Linux supports.

References:
1. C99 standard, section 6.4.4.3: enumeration = int
2. C99 section 6.2.5, marker 20: about enum = just definition of a
constant and _not_ a typed form.

So, I'd be happy with 3, can live with 2, and dislike 1 very much :-)

> Also, I'm pondering the question: do we need to worry about the
> underlying numbering for such an enum? I believe there it is
> theoretically possible for different compilers to choose a different
> numbering scheme, potentially making user-compiled software
> incompatible with the internal kernel binary. Perhaps to be safe we
> could just do:
> 
> enum {
>      MTD_OOB_PLACE = 0,
>      MTD_OOB_AUTO = 1,
>      MTD_OOB_RAW = 2,
> };

I cannot refer to a section in a standard, but I am sure unitialized
tags will start with 0 reliably. But yes, it is much less error-prone to
initialize the tags explicitly, because it makes it a bit more difficult
to make a stupid mistake by adding a new constant and change values of
other constants.

> Or instead, maybe we should just switch to a __u32 type and some #defines...

Anonymous enum is almost that, you can just treat it as int32_t.

> Sorry if this is a lot of thinking out loud here :)

Yeah, least significant topics usually cause most discussions - I was
told recently by a colleague that this is called "bike shedding". Notice
how much I wrote comparing to more important posts of yours :-)

-- 
Best Regards,
Artem Bityutskiy

  reply	other threads:[~2011-08-23  5:28 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-17 23:50 [RFC 0/5] fix data+OOB writes, add ioctl Brian Norris
2011-08-17 23:50 ` [RFC 1/5] mtd: support MTD_MODE_RAW for writing OOB Brian Norris
2011-08-22  8:35   ` Artem Bityutskiy
2011-08-22 20:08     ` Brian Norris
2011-08-23  4:47       ` Artem Bityutskiy
2011-08-23  5:25   ` Jason Liu
2011-08-23 19:57     ` Brian Norris
2011-08-17 23:50 ` [RFC 2/5] mtd: support MTD_MODE_RAW for reading OOB Brian Norris
2011-08-22  8:38   ` Artem Bityutskiy
2011-08-17 23:50 ` [RFC 3/5] mtd: do not assume oobsize is power of 2 Brian Norris
2011-08-22  8:46   ` Artem Bityutskiy
2011-08-22 20:21     ` Brian Norris
2011-08-17 23:50 ` [RFC 4/5] mtd: move mtd_oob_mode_t to shared kernel/user space Brian Norris
2011-08-22  8:50   ` Artem Bityutskiy
2011-08-22 21:43     ` Brian Norris
2011-08-23  5:30       ` Artem Bityutskiy [this message]
2011-08-23 17:24         ` Brian Norris
2011-08-17 23:50 ` [RFC 5/5] mtd: add MEMWRITEDATAOOB ioctl Brian Norris
2011-08-22  8:56   ` Artem Bityutskiy
2011-08-23  0:04     ` Brian Norris
2011-08-23  6:05       ` Artem Bityutskiy
2011-08-23  6:06       ` Artem Bityutskiy
2011-08-23  6:11       ` Artem Bityutskiy
2011-08-22 10:02 ` [RFC 0/5] fix data+OOB writes, add ioctl Artem Bityutskiy
2011-08-22 12:04   ` Ivan Djelic
2011-08-22 12:16     ` Artem Bityutskiy
2011-08-23  6:48       ` Ricard Wanderlof
2011-08-23 16:47         ` Brian Norris
2011-08-24 15:36           ` Ricard Wanderlof
2011-08-24 18:01             ` Brian Norris
2011-08-25  7:21               ` Artem Bityutskiy
2011-08-25  9:33               ` Ricard Wanderlof
2011-08-25 17:54                 ` Brian Norris
2011-08-26 12:41                   ` Ricard Wanderlof
2011-08-22 23:42   ` Brian Norris
2011-08-23  6:01     ` Artem Bityutskiy

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=1314077429.2645.31.camel@sauron \
    --to=dedekind1@gmail.com \
    --cc=b35362@freescale.com \
    --cc=cernekee@gmail.com \
    --cc=computersforpeace@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=mlcreech@gmail.com \
    --cc=vapier.adi@gmail.com \
    /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