From: Albert ARIBAUD <albert.u.boot@aribaud.net>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/3] nand: lpc32xx: add SLC NAND driver
Date: Fri, 17 Jul 2015 23:20:19 +0200 [thread overview]
Message-ID: <20150717232019.06c1db16@lilith> (raw)
In-Reply-To: <1437166134-21204-2-git-send-email-slemieux.tyco@gmail.com>
Hello Sylvain,
On Fri, 17 Jul 2015 16:48:52 -0400, slemieux.tyco at gmail.com
<slemieux.tyco@gmail.com> wrote:
> 1) Fixed checkpatch script output in legacy code.
> A single warning remaining.
> The following warning from the legacy code is still present:
> lpc32xx_nand.c:195: WARNING: Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt
> +static u_char lpc32xx_read_byte(struct mtd_info *mtd)
> +{
> + struct nand_chip *this = mtd->priv;
> + unsigned long *preg = (unsigned long *)this->IO_ADDR_R;
> + volatile unsigned long tmp32;
> + tmp32 = *preg;
> + return (u_char)tmp32;
> +}
The volatile above has no reason to exist; the warning is justified
here as we have accessors that guarantee that the access will not be
optimized away or reordered, juste like the 'volatile' above tries to
do (and yes, these accessors *use* 'volatile'. All the more a reason
not to use it again here).
Besides, the code is quite verbose and not precise enough. Yes,
'unsigned long' is 32-bit-ish, but in U-Boot, when something is 32-bit,
that is explicit.
All in all, the whole function could be expressed as:
static u_char lpc32xx_read_byte(struct mtd_info *mtd)
{
struct nand_chip *this = mtd->priv;
return (u_char)readl(this->IO_ADDR_R);
}
BTW, isn't IO_ADDR_R pointing to the data register, and isn't the data
register 16-bits? And if so, then why the 32-bits read?
Also, I did not find where the IO_ADDR_R field is assigned. Did I miss
it?
This is just one case, but I suspect in many places, the code is
unnecessarily complex. I understand it was ported, not written from
scratch, but I think porting code should not prevent us from making it
smaller, more efficient and more maintainable.
Amicalement,
--
Albert.
next prev parent reply other threads:[~2015-07-17 21:20 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-17 20:48 [U-Boot] [PATCH 1/3] nand: lpc32xx: add SLC NAND driver slemieux.tyco at gmail.com
2015-07-17 21:20 ` Albert ARIBAUD [this message]
2015-07-17 22:24 ` LEMIEUX, SYLVAIN
2015-07-17 23:01 ` Scott Wood
2015-07-17 23:10 ` Vladimir Zapolskiy
2015-07-17 23:46 ` LEMIEUX, SYLVAIN
2015-07-18 5:50 ` Albert ARIBAUD
2015-07-27 21:45 ` LEMIEUX, SYLVAIN
2015-07-28 0:21 ` Vladimir Zapolskiy
2015-07-28 16:28 ` LEMIEUX, SYLVAIN
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=20150717232019.06c1db16@lilith \
--to=albert.u.boot@aribaud.net \
--cc=u-boot@lists.denx.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