From: tj@kernel.org (Tejun Heo)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/2] ahci: imx: use macros to define registers and bits
Date: Wed, 16 Apr 2014 09:57:03 -0400 [thread overview]
Message-ID: <20140416135703.GA1257@htj.dyndns.org> (raw)
In-Reply-To: <20140416063510.GH2523@dragon>
Hello,
On Wed, Apr 16, 2014 at 02:35:12PM +0800, Shawn Guo wrote:
> I'm seeing a lot of ata drivers use defines though. And I'm not sure I
> understand the advantages of using enums over defines in ahci_imx
> driver, where register offset and bit position are defined in the same
> 'enum' without a particular enum type.
>
> enum {
> PORT_PHY_CTL = 0x178, /* Port0 PHY Control */
> PORT_PHY_CTL_PDDQ_LOC = 0x100000, /* PORT_PHY_CTL bits */
> HOST_TIMER1MS = 0xe0, /* Timer 1-ms */
> };
>
> To me it's a misuse of enum.
The difference isn't that significant but enums have the advantages of
the definitions being evaluated once rather than each time it's used
which prevents things like missing parentheses subtly messing up the
containing expressions and the compiler, and thus the debugger, being
aware of the constants in use.
The technical advantages not being enormous, it's a good bike shedding
material and argue about it back and forth forever without being
productive at all, so, please just stick with enums.
Thanks.
--
tejun
next prev parent reply other threads:[~2014-04-16 13:57 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-15 2:41 [PATCH 1/2] ahci: imx: use macros to define registers and bits Shawn Guo
2014-04-15 2:41 ` [PATCH 2/2] ahci: imx: software workaround for phy reset issue in resume Shawn Guo
2014-04-15 3:19 ` Fabio Estevam
2014-04-15 16:10 ` Tejun Heo
2014-04-16 7:38 ` Shawn Guo
2014-04-16 14:01 ` Tejun Heo
2014-04-17 2:05 ` Shawn Guo
2014-04-15 16:03 ` [PATCH 1/2] ahci: imx: use macros to define registers and bits Tejun Heo
2014-04-16 6:35 ` Shawn Guo
2014-04-16 13:57 ` Tejun Heo [this message]
2014-04-16 7:59 ` Uwe Kleine-König
2014-04-16 8:08 ` Shawn Guo
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=20140416135703.GA1257@htj.dyndns.org \
--to=tj@kernel.org \
--cc=linux-arm-kernel@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).